Reputation: 5129
I have oneToMany bidirectional relationship between User and Address. In yml file, do I need to specify the user_id field for Address entity? I did that and when I generated entity getters it didn't create getUser() or setUser() instead getUserId() and setUserId()
Upvotes: 2
Views: 2457
Reputation: 5411
On your Address
entity you would have a $user
field relating to a User
entity, not user_id
relating to an integer
.
Remember you are mapping in terms of entities with Doctrine, not SQL or relational database tables. Try to think in terms of your business model as much as possible, Doctrine will handle the rest and internally it will know to make a foreign key related to a user id in the address
table.
User mapping:
oneToMany:
addresses:
targetEntity: Address
mappedBy: user
Address mapping
manyToOne:
user:
targetEntity: User
inversedBy: addresses
Upvotes: 5