Есть две сущности:
<?php
/**
* Created by PhpStorm.
* User: leonid.groshev
* Date: 21.12.2016
* Time: 12:31
*/
namespace Atelie\Entity;
use DateTime;
use Doctrine\Common\Collections\ArrayCollection;
use Symfony\Component\Serializer\Normalizer\NormalizableInterface;
use Symfony\Component\Serializer\Normalizer\NormalizerInterface;
/**
* Class ShoesProduct
*
* @package Atelie\Entity
*
* @Entity(repositoryClass="Atelie\Doctrine\Repository\ShoesProductRepository") @Table(name="shoes_products")
* @HasLifecycleCallbacks
*/
class ShoesProduct implements NormalizableInterface
{
/**
* @var int
* @Id @Column(type="integer") @GeneratedValue
*/
protected $id;
/**
* @var string
* @Column(type="string")
*/
protected $title = '';
/**
* @var string
* @Column(type="text")
*/
protected $description = '';
/**
* @var string
* @Column(type="decimal", nullable = true, scale=2)
*/
protected $price = '';
/**
* @var string
* @Column(type="integer")
*/
protected $difficulty = '';
/**
* @var bool
* @Column(type="boolean", options={"default": true})
*/
protected $new = true;
/**
* @var bool
* @Column(type="boolean", options={"default": false})
*/
protected $sale = false;
/**
* @var bool
* @Column(type="boolean", options={"default": false})
*/
protected $hot = false;
/**
* @var bool
* @Column(type="boolean", options={"default": false})
*/
protected $recommended = false;
/**
* @var string
* @Column(type="integer", options={"default": 0})
*/
protected $likes = 0;
/**
* @var DateTime
* @Column(type="datetime")
*/
protected $created_at;
/**
* @var DateTime
* @Column(type="datetime", nullable = true)
*/
protected $updated_at;
/**
* @var bool
* @Column(type="boolean", options={"default": false})
*/
protected $deleted = false;
/**
* Relations
*/
/**
* @var Document[]|ArrayCollection
* @ManyToMany(targetEntity="Document")
*/
protected $documents;
/**
* @var Textile
* @ManyToOne(targetEntity="Textile")
*/
protected $textile;
/**
* @var Purpose
* @ManyToOne(targetEntity="Purpose")
*/
protected $purpose;
/**
* @var Gender
* @ManyToOne(targetEntity="Gender")
*/
protected $gender;
/**
* @var Season
* @ManyToOne(targetEntity="Season")
*/
protected $season;
/**
* @var Type
* @ManyToOne(targetEntity="Type")
*/
protected $type;
/**
* @var Category
* @ManyToOne(targetEntity="Category")
*/
protected $category;
/**
* @var Brand
* @ManyToOne(targetEntity="Brand")
*/
protected $brand;
/**
* One Country has Many Regions.
* @OneToMany(targetEntity="ShoesModel", mappedBy="shoes_product")
*/
protected $shoes_models;
function __construct()
{
$this->documents = new ArrayCollection();
$this->shoes_models = new ArrayCollection();
}
/**
* @return ShoesModel[]|ArrayCollection
*/
public function getShoesModels()
{
return $this->shoes_models;
}
/**
* @param ShoesModel[] $shoes_models
* @return $this
*/
public function setShoesModels($shoes_models)
{
$this->shoes_models = $shoes_models;
return $this;
}
/**
* @return int
*/
public function getId()
{
return $this->id;
}
/**
* Create and Update time
* @PrePersist
* @PreUpdate
*/
public function updatedTimestamps()
{
if ($this->created_at == null) {
$this->created_at = new DateTime('now');
}
else {
$this->updated_at = new DateTime('now');
}
}
/**
* @return DateTime
*/
public function getCreatedAt()
{
return $this->created_at;
}
/**
* @return DateTime
*/
public function getUpdatedAt()
{
return $this->updated_at;
}
/**
* @return string
*/
public function getTitle()
{
return $this->title;
}
/**
* @param string $title
* @return $this
*/
public function setTitle($title)
{
$this->title = $title;
return $this;
}
/**
* @return string
*/
public function getDescription()
{
return $this->description;
}
/**
* @param string $description
* @return $this
*/
public function setDescription($description)
{
$this->description = $description;
return $this;
}
/**
* @return string
*/
public function getPrice()
{
return $this->price;
}
/**
* @param string $price
* @return $this
*/
public function setPrice($price)
{
$this->price = $price;
return $this;
}
/**
* @return string
*/
public function getDifficulty()
{
return $this->difficulty;
}
/**
* @param string $difficulty
* @return $this
*/
public function setDifficulty($difficulty)
{
$this->difficulty = $difficulty;
return $this;
}
/**
* @return Document[]
*/
public function getDocuments()
{
return $this->documents;
}
/**
* @param Document[] $documents
* @return $this
*/
public function setDocuments($documents)
{
$this->documents = $documents;
return $this;
}
/**
* @return Textile
*/
public function getTextile()
{
return $this->textile;
}
/**
* @param Textile $textile
* @return $this
*/
public function setTextile($textile)
{
$this->textile = $textile;
return $this;
}
/**
* @return Purpose
*/
public function getPurpose()
{
return $this->purpose;
}
/**
* @param Purpose $purpose
* @return $this
*/
public function setPurpose($purpose)
{
$this->purpose = $purpose;
return $this;
}
/**
* @return Gender
*/
public function getGender()
{
return $this->gender;
}
/**
* @param Gender $gender
* @return $this
*/
public function setGender($gender)
{
$this->gender = $gender;
return $this;
}
/**
* @return Season
*/
public function getSeason()
{
return $this->season;
}
/**
* @param Season $season
* @return $this
*/
public function setSeason($season)
{
$this->season = $season;
return $this;
}
/**
* @return Type
*/
public function getType()
{
return $this->type;
}
/**
* @param Type $type
* @return $this
*/
public function setType($type)
{
$this->type = $type;
return $this;
}
/**
* @return Category
*/
public function getCategory()
{
return $this->category;
}
/**
* @param Category $category
* @return $this
*/
public function setCategory($category)
{
$this->category = $category;
return $this;
}
/**
* @return Brand
*/
public function getBrand()
{
return $this->brand;
}
/**
* @param Brand $brand
* @return $this
*/
public function setBrand($brand)
{
$this->brand = $brand;
return $this;
}
/**
* @return string
*/
public function isNew()
{
return $this->new;
}
/**
* @param string $new
* @return $this
*/
public function setNew($new)
{
$this->new = $new;
return $this;
}
/**
* @return string
*/
public function onSale()
{
return $this->sale;
}
/**
* @param string $sale
* @return $this
*/
public function setSale($sale)
{
$this->sale = $sale;
return $this;
}
/**
* @return string
*/
public function isHot()
{
return $this->hot;
}
/**
* @param string $hot
* @return $this
*/
public function setHot($hot)
{
$this->hot = $hot;
return $this;
}
/**
* @return string
*/
public function isRecommended()
{
return $this->recommended;
}
/**
* @param string $recommended
* @return $this
*/
public function setRecommended($recommended)
{
$this->recommended = $recommended;
return $this;
}
/**
* @return string
*/
public function getLikes()
{
return $this->likes;
}
/**
* @param string $likes
* @return $this
*/
public function setLikes($likes)
{
$this->likes = $likes;
return $this;
}
/**
* @return boolean
*/
public function isDeleted()
{
return $this->deleted;
}
/**
* @param boolean $deleted
*/
public function setDeleted($deleted)
{
$this->deleted = $deleted;
}
/**
* Normalizes the object into an array of scalars|arrays.
*
* It is important to understand that the normalize() call should normalize
* recursively all child objects of the implementor.
*
* @param NormalizerInterface $normalizer The normalizer is given so that you
* can use it to normalize objects contained within this object.
* @param string|null $format The format is optionally given to be able to normalize differently
* based on different output formats.
* @param array $context Options for normalizing this object
*
* @return array
*/
public function normalize(NormalizerInterface $normalizer, $format = null, array $context = array())
{
$result['id'] = $this->getId();
$result['title'] = $this->getTitle();
$result['description'] = $this->getDescription();
$result['price'] = $this->getPrice();
$result['difficulty'] = $this->getDifficulty();
$result['documents'] = $normalizer->normalize($this->getDocuments());
$result['textile'] = $normalizer->normalize($this->getTextile());
$result['purpose'] = $normalizer->normalize($this->getPurpose());
$result['gender'] = $normalizer->normalize($this->getGender());
$result['season'] = $normalizer->normalize($this->getSeason());
$result['type'] = $normalizer->normalize($this->getType());
$result['category'] = $normalizer->normalize($this->getCategory());
$result['brand'] = $normalizer->normalize($this->getBrand());
$result['new'] = $this->isNew();
$result['sale'] = $this->onSale();
$result['hot'] = $this->isHot();
$result['recommended'] = $this->isRecommended();
$result['likes'] = $this->getLikes();
$result['created_at'] = $this->getCreatedAt();
$result['updated_at'] = $this->getUpdatedAt();
$result['shoes_models'] = $normalizer->normalize($this->getShoesModels());
$result['deleted'] = $this->isDeleted();
$result['class'] = 'shoes-product';
return $result;
}
}
<?php
/**
* Created by PhpStorm.
* User: leonid.groshev
* Date: 21.12.2016
* Time: 12:31
*/
namespace Atelie\Entity;
use DateTime;
use Doctrine\Common\Collections\ArrayCollection;
use Symfony\Component\Serializer\Normalizer\NormalizableInterface;
use Symfony\Component\Serializer\Normalizer\NormalizerInterface;
/**
* Class ShoesModel
*
* @package Atelie\Entity
*
* @Entity @Table(name="shoes_models")
* @HasLifecycleCallbacks
*/
class ShoesModel implements NormalizableInterface
{
/**
* @var int
* @Id @Column(type="integer") @GeneratedValue
*/
protected $id;
/**
* @var DateTime
* @Column(type="datetime")
*/
protected $created_at;
/**
* @var DateTime
* @Column(type="datetime", nullable = true)
*/
protected $updated_at;
/**
* @var bool
* @Column(type="boolean", options={"default": false})
*/
protected $deleted = false;
/**
* Relations
*/
/**
* @var Document[]|ArrayCollection
* @ManyToMany(targetEntity="Document")
*/
protected $documents;
/**
* @var ShoesSize
* @ManyToOne(targetEntity="ShoesSize")
*/
protected $size;
/**
* @var ShoesProduct
* @ManyToOne(targetEntity="ShoesProduct")
*/
protected $shoes_product;
function __construct()
{
$this->documents = new ArrayCollection();
}
/**
* @return ShoesProduct
*/
public function getShoesProduct()
{
return $this->shoes_product;
}
/**
* @param ShoesProduct $shoes_product
* @return $this
*/
public function setShoesProduct($shoes_product)
{
$this->shoes_product = $shoes_product;
return $this;
}
/**
* @return int
*/
public function getId()
{
return $this->id;
}
/**
* Create and Update time
* @PrePersist
* @PreUpdate
*/
public function updatedTimestamps()
{
if ($this->created_at == null) {
$this->created_at = new DateTime('now');
}
else {
$this->updated_at = new DateTime('now');
}
}
/**
* @return DateTime
*/
public function getCreatedAt()
{
return $this->created_at;
}
/**
* @return DateTime
*/
public function getUpdatedAt()
{
return $this->updated_at;
}
/**
* @return Document[]
*/
public function getDocuments()
{
return $this->documents;
}
/**
* @param Document[] $documents
* @return $this
*/
public function setDocuments($documents)
{
$this->documents = $documents;
return $this;
}
/**
* @return ShoesSize
*/
public function getShoesSize()
{
return $this->size;
}
/**
* @param ShoesSize $size
* @return $this
*/
public function setShoesSize($size)
{
$this->size = $size;
return $this;
}
/**
* @return boolean
*/
public function isDeleted()
{
return $this->deleted;
}
/**
* @param boolean $deleted
*/
public function setDeleted($deleted)
{
$this->deleted = $deleted;
}
/**
* Normalizes the object into an array of scalars|arrays.
*
* It is important to understand that the normalize() call should normalize
* recursively all child objects of the implementor.
*
* @param NormalizerInterface $normalizer The normalizer is given so that you
* can use it to normalize objects contained within this object.
* @param string|null $format The format is optionally given to be able to normalize differently
* based on different output formats.
* @param array $context Options for normalizing this object
*
* @return array
*/
public function normalize(NormalizerInterface $normalizer, $format = null, array $context = array())
{
$result['id'] = $this->getId();
$result['documents'] = $normalizer->normalize($this->getDocuments());
$result['created_at'] = $this->getCreatedAt();
$result['updated_at'] = $this->getUpdatedAt();
$result['size'] = $normalizer->normalize($this->getShoesSize());
$result['shoes_product'] = $normalizer->normalize($this->getShoesProduct());
$result['deleted'] = $this->isDeleted();
$result['class'] = 'shoes-product';
return $result;
}
}
При использовании связи @OneToMany
и вызове метода getShoesModels
сервер возвращает ошибку 502.
Если отключить вызов метода getShoesModels
- то все работает нормально и возвращает нормальный ответ.
В чем может быть причина?
Айфон мало держит заряд, разбираемся с проблемой вместе с AppLab
Перевод документов на английский язык: Важность и ключевые аспекты
Какие существуют виды рекламных бордов и как выбрать подходящий?
есть скрипт /usr/local/vesta/bin/v-add-user из под sudo работаетего права
Как удалить записи из бд сделанные сегодня? То бишь после 00:00
Попытка асинхронно отправить данные с помощью fsockopen() не проходит: без fgets() не работает, а с fgets()уже перестает быть асинхронным
Пытаюсь вернуть JSON ответ, но при попытке получения, выдает