On 17 June 2015 at 08:52, Sérgio Amorim <[email protected]> wrote: > Hi Marco and thank you for your reply. > > But the question still stands because there are other examples that it > makes sense. So, can lazy loading be turn off? >
No, it's one of the base mechanisms of the ORM, and it's not meant to be configurable. > Another example, lets say for instance that I retrieve Bar but I forgot to > include Qux in the DQL, and thus, when accessing the getQuxs() it will make > the additional call to the database. > You need to look up "Fetch Joins" about that: http://docs.doctrine-project.org/projects/doctrine-orm/en/latest/reference/dql-doctrine-query-language.html#joins I also wrote about it at https://ocramius.github.io/blog/doctrine-orm-optimization-hydration/ > If I turn off my lazy loading then I my unit test will fail because Quxs > is empty when expecting data and I can guarantee that I only make the > amount calls that I intended and not any other. > Why do your unit tests use the persistence layer in first place (when not testing repositories)? Sounds like your models allow too much? > Otherwise, I could potentially have a bunch of calls to the database > without my "consent". I know also this particular problem I might include a > solution for profiling the amount of calls, but again, deviating from the > question. > The number of calls is an implementation detail that you can tweak/optimize, but it is still an implementation detail, and you shouldn't worry about it from a consumer perspective. As for the business logic, whenever you are tempted to push something down into the ORM internals/hooks, think: "would it make sense to add this sort of logic to serialize() and unserialize()?". It's a good rule of thumb :-) Marco Pivetta http://twitter.com/Ocramius http://ocramius.github.com/ -- You received this message because you are subscribed to the Google Groups "doctrine-user" group. To unsubscribe from this group and stop receiving emails from it, send an email to [email protected]. To post to this group, send email to [email protected]. Visit this group at http://groups.google.com/group/doctrine-user. For more options, visit https://groups.google.com/d/optout.
