Reputation: 814
I have a entity called Venues and other called Users. Each Venue has one field called User which is the owner of the venue and is one of the users. On the other side each User has a Venue field, including the original venue where he signed up. So I'm trying to sort out what's the proper yml config.
On the venue.orm.yml file I have
manyToOne: user: targetEntity: Users joinColumns: User: referencedColumnName: ID inverseJoinColumns: ID: referencedColumnName: User orphanRemoval: false
And on the users.orm.yml I got:
manyToOne: venue: targetEntity: Venues joinColumns: Venue: referencedColumnName: ID inverseJoinColumns: ID: referencedColumnName: Venue orphanRemoval: false
The app fails silently, stopping the rendering of the view, just when form_start(form). I'm not able to see the web profiler (as usual) although I'm on dev mode. If I remove the field User from venue, then the render will be ok. Please let me know what I'm missing since I can't find a proper example under doctrine or symfony docs, and I think that I'm misunderstanding this link http://mnapoli.fr/doctrine-2-yaml-reference/ Thanks in advance ;)
EDIT The cause of the failure was a Memory Exhaust type error so this issue was at first provisionally solved by increasing the php.ini memory limit to 220MB,but as I need to set it back to 64MB limit, I found that by explicitly declaring all the types and entity options of my formType, the memory overhead was dramatically reduced. In addition I have limited the total options available at some selects, using query builder in the formType. Anyway I'll look forward for any additional action oriented to the memory saving. I'm going to google for any select options lazyloader Symfony component...
Upvotes: 1
Views: 329
Reputation: 1165
use mappedBy on the inverse side and inversedBy on the owning side.
venue.orm.yml
manyToOne:
user:
targetEntity: Users
joinColumns:
User:
referencedColumnName: ID
inversedBy:venue
orphanRemoval: false
users.orm.yml
oneToMany:
venue:
targetEntity: Venues
joinColumns:
Venue:
referencedColumnName: ID
mappedBy: user
orphanRemoval: false
Be careful:
joinColumns:
X:
referencedColumnName: Y
X and Y are sql table fields, X field of Entity field, Y referenced entity field.
Regards
Upvotes: 0
Reputation: 20193
manyToOne:
user: <-- CLASS MEMBER NAME
targetEntity: Users
joinColumns:
user: <-- DATABASE COLUMN NAME
referencedColumnName: id <-- DATABASE COLUMN NAME
Be sure that you haven't misplaced class member name
for database column name
.
Also, your original YAML
seems to be a bit more complicated that it should be. As far as I know, joinColumns
and inverseJoinColumns
should be used together only in case of joined tabled (@ManyToMany
) which is clearly not your case.
The fact that it fails so silently points to some severe error, although I cannot be even guess why it does not log it.
Do you, by any chance, have xdebug
enabled? I've just remembered having some problems with recursion level limit within xdebug
and php
terminating silently.
If you do, see this question on how to increase it: Increasing nesting function calls limit
Upvotes: 1