-
Notifications
You must be signed in to change notification settings - Fork 2.5k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
[POSSIBLE BUG] setFetchMode not overriding fetch annotation #7860
Comments
The documentation mentions the behaviour of oneToMany relation when the fetch mode is set to to eager, but not how it behaves when set to lazy. Thank you for reporting this. |
Thanks for the link, @SenseException, I can't believe I missed that part of the documentation 😓 I've been able to (partially) get around this by using JMSSerializer groups to avoid unnecessary resolution and hydration of relationships and properties. |
Hi Has there been any progress on this issue? I would like to use this feature to set a lazy association to extra lazy hydration. |
This comment was marked as spam.
This comment was marked as spam.
The bug still exists even in ORM 3. The FetchMode from ClassMetadata must be overriden from |
Bug Report
Summary
I have the following entities:
IntervalGroup
w/ oneToMany relation toIntervalType
(fetch:EXTRA_LAZY
)IntervalType
w/ oneToMany relation toInterval
(fetch:EXTRA_LAZY
)Interval
w/ oneToMany relation toTask
(fetch:EAGER
)On the
IntervalGroup
repository I'm doing a DQL Query Builder query to load allIntervalGroup
s, and left joinIntervalGroup.intervalTypes
andintervalTypes.interval
.By default, the
Task
relation onInterval
will be eager-loaded during hydration, however I don't wantTask
s in this case. To counter that I'm usingsetFetchMode()
on theQuery
object like so:Which, as I understand, should prevent the ORM from fetching and hydrating those relations in that query.
Current behavior
Currently, the query hint for the fetch mode is not overriding the fetch mode on the annotation, so Doctrine loads the
Interval.tasks
relation.createEntity
in theUnitOfWork
class is using thefetch
value from the annotation, instead of the fetchMode query hint:(as seen here)
When I
dump($assoc)
I can see for thetargetEntity = "Task"
that$assoc['fetch']
equals3
(ClassMetadata::FETCH_EAGER
) when I specified insetFetchMode()
that it should be2
(ClassMetadata::FETCH_LAZY
).How to reproduce
Expected behavior
The fetch mode override (as set in
setFetchMode()
) should be respected during hydration.UnitOfWork::createEntity
's$assoc['fetch']
should check the$hints
array to see if it is overridden, or use the default annotation value if not.I believe overriding a
fetch
annotation should be possible to do, though perhaps I'm doing it the wrong way (in which case I'm happy to be pointed in the right direction!).The text was updated successfully, but these errors were encountered: