Marco, Thanks once again.
It's always a trade off between control on the app vs complexity of the library, but if is not possible then.. it's not. At least now I know! :) The problem comes down to doing a query in the DAL returning that object up the chain and nothing will prevent another call to the database access layer... so it goes out of control of the DAL. Potentially, a view layer could promote calls to the database and there's nothing that can be done in the layers between to "control" it. All because the entity model are wrap in a proxy that does this and you "can't turn off". By the way, Entity Framework (DBAL of the .NET world) enables you to do this by disabling the proxy and hydrating directly the model entities. Of course this has it's side effects, like you potentially could think that there are no Qux, because the collection won't be populated, when there are. But you have the control of it. Do you think that is feasible to create a proxy factory that disables this? Or a custom hydration that doesn't use the proxy? Regards, Sérgio -- *Sérgio Amorim* Twitter: #saamorim Tel: +351 916091384 pt.linkedin.com/in/saamorim/ https://www.freelancer.com/u/saamorim.html Msn, gtalk, email: [email protected] skype: saamorim - 2015-06-17 8:57 GMT+01:00 Marco Pivetta <[email protected]>: > 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 a topic in the > Google Groups "doctrine-user" group. > To unsubscribe from this topic, visit > https://groups.google.com/d/topic/doctrine-user/ak-2UuRDciE/unsubscribe. > To unsubscribe from this group and all its topics, 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. > -- 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.
