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? 

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. 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. 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.


Regards,
Sérgio



On Wednesday, June 17, 2015 at 12:31:09 AM UTC+1, Marco Pivetta wrote:
>
> Hello Sérgio,
>
> I think that you are fundamentally solving the wrong problem here: mixing 
> the domains of persistence and ACL/RBAC.
>
> Make your business rules explicit and enforced by object API internals, 
> rather than pushing this sort of logic down the ORM.
>
> Marco Pivetta 
>
> http://twitter.com/Ocramius      
>
> http://ocramius.github.com/
>
> On 17 June 2015 at 00:21, Sérgio Amorim <[email protected] <javascript:>> 
> wrote:
>
>> Hi.
>>
>> Quite a few posts out there asking how you can disable lazy loading, but 
>> most of all turn in a direction to use the the hydration mode array. 
>> Unfortunatly, this doesn't enable me to use the generated entity classes 
>> that I already defined for doctrine and doesn't allow a proper interface to 
>> be set
>>
>> Details:
>>
>> Assume that I defined the entities
>>
>> namespace Foo\Entity;
>> class Qux {
>>    protected $extraData;
>>    public getExtraData() { ...}
>>    public setExtraData($extraData) { ...}
>> }
>>
>> class Bar {
>>
>>    protected $quxs;
>>    public addQux(Qux $qux) { ... }
>>    public removeQux(Qux $qux) { ... }
>>    public getQuxs() { ... } 
>> }
>>
>>
>>
>>
>> Lets say that depending on the context (for instance, for security 
>> reasons) the service layer decides to call either call database layer that 
>> has two methods NoDetails or Complete.
>>
>> /**
>>  * @returns Bar[]
>>  **/
>> public fetchBar($context) {
>>    if($this->security->hasFullAccess($context))
>>       return $this->dbal->getBarComplete();
>>    else
>>       return $this->dbal->getBarNoDetails();
>> }
>>
>> which are implemented as followed:
>>
>> /**
>>  * @returns Bar[]
>>  **/
>> public getBarNoDetails() {
>>    $entityManager->createNativeQuery("Select b from Foo:Bar b")->
>> getResults();
>> }
>>
>> /**
>>  * @returns Bar[]
>>  **/
>> public getBarComplete() {
>>    $entityManager->createNativeQuery("Select b,q from Foo:Bar b join 
>> b.Qux q")
>> ->getResults();
>> }
>>
>>
>>
>>
>> Now, since I've set to use lazy loading I'm not really creating a 
>> difference to the poing of view of the caller, since, in both scenarios he 
>> can still do
>>
>> $bars[0]->getQuxs() 
>>
>> the only difference would be that it would take longer to respond 
>> because of the lazy loading.
>>
>> But, if I use 
>>
>>  ...->getArrayResults();
>>
>> I manage to sucessfully restrict the access to the Qux collection, but 
>> now the interface is broken, because I'm not returning a set of 
>> Foo\Entity\Bar[] but instead an array. And cannot longer to $bars[0]->
>> getQuxs() and I must use instead $bars[0]->quxs. 
>>
>> Thoughts?
>>
>> Thx
>>
>> -- 
>> 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] <javascript:>.
>> To post to this group, send email to [email protected] 
>> <javascript:>.
>> 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.

Reply via email to