tags:

views:

23

answers:

1

It looks like when I forget to put leftJoin in my queries, Doctrine will lazy-load relations after I pick them. Ie if I do something like:

$property = PropertyTable::getInstance()->createQuery('o')
  ->leftJoin('o.Features f')
  ->execute() ;

I will still be able to access $property->Attraction , even if I didn't load them in this query. So I guess Doctrine does it internally by calling another 'SELECT'. Is there a way to prevent this auto-loading by throwing some exception? This would help me create better and faster queries.

A: 

Have you looked at the actual sql it produces?

Try ->getSql(). It is likely it is doing another query when you attempt to access a related field.

If you want to avoid that, don't access related fields!

Byron Whitlock
Yes, I have tried that and no, it doesn't load Attraction's. But I am able to access them via $property->Attraction . I would like some exception thrown so I can't make a mistake when I write a query. As I make really big programs, it is very easy to skip something like that.
Zeljko
I believe you can access them because it triggers a new query, and it is therefore intended behaviour. I think the solution here is not the change the machine, but to pay more attention to how you use the machine.
Tom
Yes, but the idea is to prevent auto-fetching. It is very easy to skip some join in quick-development of big programs.
Zeljko