Reputation: 539
I have a model with three main elements: Questions, Answers and Games. Each of them whould have Tags associated, but those Tags needs to be shared. I mean, the same tags should be used for the three kind of elements: the "Science" tag should be applied to either a Question, an Answer or a Game, or the three of them.
How should I do this? Do I add a ManyToMany field in the Tags entity for each kind of element, or is there any other way to relate them? Any idea?
Upvotes: 1
Views: 108
Reputation: 1330
I would choose option 1) add ManyToMany relationship on each entities.
class Question
{
// ...
/**
* @ORM\ManyToMany(targetEntity="Tag")
*
**/
private $tags;
}
class Answer
{
// ...
/**
* @ORM\ManyToMany(targetEntity="Tag")
*
**/
private $tags;
}
class Game
{
// ...
/**
* @ORM\ManyToMany(targetEntity="Tag")
*
**/
private $tags;
}
Upvotes: 1