3

I have 3 entities:

  • Song
  • Artist
  • Genre

One song can have multiple genres and vice versa. A song can also have multiple artists and vice versa.

That's why I'm trying to create two many-to-many relationships. However, when generating the Entity clases, the first of the two is always 'overridden' by the second one and no variable or accessors are created for that one..

Here's my yaml: (updated)

Foo\BarBundle\Entity\Song: type: entity table: song id: id: type: integer generator: strategy: AUTO fields: title: type: string length: 300 mime_type: type: string length: 20 filesize: type: integer length: 20 length: type: string length: 20 created_at: type: datetime gedmo: timestampable: on: create manyToOne: user: targetEntity: Spotaset\UserBundle\Entity\User inversedBy: songs manyToMany: genres: targetEntity: Genre inversedBy: songs manyToMany: artists: targetEntity: Artist inversedBy: songs Foo\BarBundle\Entity\Artist: type: entity table: artist id: id: type: integer generator: strategy: AUTO fields: name: type: string length: 100 unique: true manyToMany: songs: targetEntity: Song mappedBy: artistss Foo\BarBundle\Entity\Genre: type: entity table: genre id: id: type: integer generator: strategy: AUTO fields: name: type: string length: 100 unique: true manyToMany: songs: targetEntity: Song mappedBy: genres 

I don't know a lot about relational databases so I don't know wether this is a bug or that this design is just bad in general..

All help is greatly appreciated!

1
  • 4
    I have always found that the MasnyToMany relations with the automatic creation of the join table to be too much magic for my tastes. I explictly create the join entity and then use simple OneToMany / ManyToOne relations. Commented Mar 2, 2012 at 1:13

1 Answer 1

9

Finally solved this (stupid) issue. Turned out I had to define both many to many under one manyToMany heading like this:

 manyToMany: genres: targetEntity: Genre inversedBy: songs artists: targetEntity: Artist inversedBy: songs 
Sign up to request clarification or add additional context in comments.

1 Comment

This is because yaml does not handle dublicated keys and simply overrites them. This is very good when inheriting configs (see config.yml and config_prod.yml as an example).

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.