【发布时间】:2016-12-09 00:11:56
【问题描述】:
我正在尝试使用 Doctrine 2 + Symfony 创建这三个类,并带有双向 YAML 映射。
一切正常,没有错误,但生成的实体仅包含 User 实体的前两个集合声明。该实体也没有缺失链接的添加、删除和获取功能。
我尝试分别生成每个映射,工作正常。
这是 Doctrine2 的限制吗?
生成的 MyBundle\Entity\User.php 构造函数(缺少 Token 类的 ArrayCollection):
public function __construct()
{
$this->owned = new \Doctrine\Common\Collections\ArrayCollection();
$this->shared = new \Doctrine\Common\Collections\ArrayCollection();
}
Collection.orm.yml:
MyBundle\Entity\Collection:
type: entity
table: collection
id:
collection_id:
type: integer
generator:
strategy: AUTO
fields:
...
manyToOne:
owner:
targetEntity: User
inversedBy: owned
joinColumn:
name: user_id
referencedColumnName: user_id
manyToMany:
shares:
targetEntity: User
inversedBy: shared
joinTable:
name: shares
joinColumns:
collection_id:
referencedColumnName: collection_id
inverseJoinColumns:
user_id:
referencedColumnName: user_id
Token.orm.yml:
MyBundle\Entity\Token:
type: entity
table: token
id:
token_id:
type: integer
generator:
strategy: AUTO
fields:
...
manyToOne:
user:
targetEntity: User
inversedBy: tokens
joinColumn:
name: user_id
referencedColumnName: user_id
用户.orm.yml:
MyBundle\Entity\User:
type: entity
table: user
id:
user_id:
type: integer
generator:
strategy: AUTO
fields:
...
oneToMany:
owned:
targetEntity: Collection
mappedBy: owner
oneToMany:
tokens:
targetEntity: Token
mappedBy: user
manyToMany:
shared:
targetEntity: Collection
mappedBy: shares
【问题讨论】:
标签: symfony doctrine-orm yaml