symfony2中有多个多对多的关系

Tho*_*s K 3 relational-database symfony doctrine-orm

我有3个实体:

  • 歌曲
  • 艺术家
  • 类型

一首歌可以有多种类型,反之亦然.一首歌也可以有多位艺术家,反之亦然.

这就是我试图建立两个多对多关系的原因.但是,在生成Entity clases时,第二个中的第一个总是被第二个"覆盖",并且没有为该那个创建变量或访问器.

这是我的yaml :( 更新)

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
Run Code Online (Sandbox Code Playgroud)

我不太了解关系数据库,所以我不知道这是一个错误还是这个设计一般都不好...

非常感谢所有帮助!

Tho*_*s K 9

终于解决了这个(愚蠢的)问题.原来我必须在一个manyToMany标题下定义多个到多个,如下所示:

  manyToMany:
    genres:
      targetEntity: Genre
      inversedBy: songs
    artists:
      targetEntity: Artist
      inversedBy: songs
Run Code Online (Sandbox Code Playgroud)

  • 这是因为yaml不处理被公开的密钥并且只是过度使用它们.这在继承configs时非常好(请参阅config.yml和config_prod.yml作为示例). (4认同)