Answer the question
In order to leave comments, you need to log in
Dynamic data in JsonApi from Doctrine-Model - how?
Good time, colleagues!
Available : Symfony 3.3, Doctrine 2.5, Neomerx/JsonApi 1.0.
Now : The User model has tabs (you can add different types of entities to them, including other users). With Doctrine and the IFavouritable interface, they are represented as a one-to-many relationship like this:
trait HasFavorites
{
/**
* @var ArrayCollection
* @ORM\OneToMany(targetEntity="AppBundle\Entity\Favorite", mappedBy="user")
*/
protected $favorites;
public function getFavorites() : Collection { return $this->favorites; }
public function addFavorite(Favorite $favorite) { $this->favorites->add($favorite); }
public function removeFavorite(Favorite $favorite) { $this->favorites->removeElement($favorite); }
}
Answer the question
In order to leave comments, you need to log in
I am for the first option:
- Inject a repository with favorites into the OrderNormalizer
- When serializing the entity, we pull out all the favorites of the logged in user and put them in the cache
- During subsequent serialization, after the favorites, we already go to the cache, and not to the database
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question