user3202924
user3202924

Reputation: 1

Relation between two entities

I search how i can do relation many to one on 2 entity different.

Look my exemple for understand.

enter image description here

Upvotes: 0

Views: 63

Answers (1)

Praveesh
Praveesh

Reputation: 1327

As per the diagram,

One article can have many comments and one video can have many comments. So, the comment entity have many to one relation with video entity and article entity.

If you are doctrine and yaml metadata files for entities, define the relations in the yaml file for Comments as given below

manyToOne:
    article:
      targetEntity: Path\to\ArtcleBunlde\Entity\Article
      joinColumn:
         name: article
         referencedColumnName: id
    video:
      targetEntity: Path\to\VideoBundle\Entity\Video
      joinColumn:
         name: video
         referencedColumnName: id 

Upvotes: 1

Related Questions