我有两个实体:
Brs\UserBundle\Entity\User:
type: entity
table: user
repositoryClass: Brs\UserBundle\Entity\UserRepository
id:
id:
type: integer
generator: { strategy: AUTO }
fields:
username:
type: string
length: 50
fname:
type: string
length: 30
lname:
type: string
length: 30
email:
type: string
length: 75
mobile:
type: string
length: 20
active:
type: boolean
mentor:
type: boolean
roll:
type: string
length: 10
profitPercentage:
type: string
length: 10
initialized:
type: datetime
password:
type: string
length: 255
oneToMany:
requests:
targetEntity: Brs\FundingBundle\Entity\Request
mappedBy: requests
和
Brs\FundingBundle\Entity\Request:
type: entity
table: null
repositoryClass: Brs\FundingBundle\Entity\RequestRepository
id:
id:
type: integer
id: true
generator:
strategy: AUTO
fields:
amount:
type: integer
status:
type: integer
datetime:
type: datetime
note:
type: string
length: 255
approval:
type: boolean
manyToOne:
user:
targetEntity: Brs\UserBundle\Entity\User
inversedBy: user
lifecycleCallbacks: { }
在Brs \ FundingBundle \ Entity \ Request:
我声明了属性:
private $user;
和Brs \ FundingBundle \ Entity \ User:
我声明了属性:
private $requests;
当我跑步时:
php app/console doctrine:schema:update --force
我得到以下结果:
Updating database schema...
Database schema updated successfully! "3" queries were executed
这看起来很好,这会创建requests表并将user_id外键添加到它,这就是我想要的。
但是我已经仔细考虑了Doctrine 2 association mapping上的文档,我似乎无法自信地理解反向,拥有和映射的逻辑。
如果有人能够对我上面的例子进行彻底解释,我们将不胜感激。
因此,在这种情况下,用户有很多请求。
提前致谢。