I have 2 entities:
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
and:
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: { }
in Brs\\FundingBundle\\Entity\\Request:
I have the property declared:
private $user;
and in Brs\\FundingBundle\\Entity\\User:
I have the property declared:
private $requests;
When I run:
php app/console doctrine:schema:update --force
I get the following result:
Updating database schema...
Database schema updated successfully! "3" queries were executed
Which seems fine, This creates the requests table and adds the user_id foreign key to it which is what I want.
However I have mulled over the documentation over at Doctrine 2 association mapping and I cannot seem to understand confidently the inverse, owning and mappedBy logic.
If someone could explain this with regards to my example above thoroughly It would be greatly appreciated.
So in this instance a user has many requests.
Thanks in advance.
Read this .
Probably using annotations will be more convenient.
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.