【发布时间】:2012-01-12 06:38:42
【问题描述】:
我正在尝试使用连接表在用户和角色之间创建一对多关系。 我还没有设法在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: { }
【问题讨论】:
-
是否正在尝试将相同的关系从 SF1 迁移到 SF2?