我尝试使用连接表在用户和角色之间创建一对多关系。 我没有能够在doctrine docs
中找到YAML示例我如何宣布与YAML的等效关系?
/**
* @ORM\ManyToMany(targetEntity="Role")
* @ORM\JoinTable(name="user_role",
* joinColumns={@ORM\JoinColumn(name="user_id", referencedColumnName="id")},
* inverseJoinColumns={@ORM\JoinColumn(name="role_id", referencedColumnName="id")}
* )
*
* @var ArrayCollection $userRoles
*/
protected $userRoles;
YAML文件:
Acme\AcmeBundle\User:
type: entity
table: null
fields:
id:
type: integer
id: true
generator:
strategy: AUTO
forename:
type: string
length: 255
surname:
type: string
length: 255
email:
type: string
length: 255
lifecycleCallbacks: { }
Acme\AcmeBundle\Role:
type: entity
table: null
fields:
id:
type: integer
id: true
generator:
strategy: AUTO
name:
type: string
length: 255
createdAt:
type: datetime
lifecycleCallbacks: { }
答案 0 :(得分:1)
这是你要找的吗?
Acme\AcmeBundle\User:
type: entity
manyToMany:
roles:
targetEntity: Role
joinTable:
name: user_role
joinColumns:
user_id:
referencedColumnName: id
inverseJoinColumns:
role:
referencedColumnName: id
table: null
fields:
id:
type: integer
id: true
generator:
strategy: AUTO
forename:
type: string
length: 255
surname:
type: string
length: 255
email:
type: string
length: 255
lifecycleCallbacks: { }