Im having a couple of MANY to MANY relations set in the model and lazy loading is fine for most of the situation.
There is a special one, when Im using this model as source for CActiveDataProvider and relations are there completely unnecessary. It is possible to stop lazy loading of relations for a certain situation? Its causing worthless impact on server resources.
I was looking through CDBCriteria documentation to find something useful, but I failed. Is it possible at all?
Can it be solved by using other source for CActiveDataProvider? Not a model itself?
I do not really understand, as I think that: Lazy loading is a design pattern commonly used in computer programming to defer initialization of an object until the point at which it is needed (extracted from Wikipedia).
Just make sure you dont do a call on the .with(‘relation’)… as that is eager loading and then…
IMHO that resource eating could be something else…
I see all that lazy loading stuff using CWebLogRoute - and I don’t want it to consume resources somewhere where it is not needed.
CActiveDataProvider provides data for CListView. In the web log I can see “lazy loading Video.tags” even if I’m not using $data->tags (M2M relation) anywhere in CListView itemView files…
Is it bug or not? I thought that lazy loading approaches only when relational property is accessed. It is not accessed in my case.
Your code must somewhere access the related record - otherwhise the lazy loading would not occur. So you should investigate further. Lazy loading works just fine and never loads a related record if it’s not accessed.
Ah, Mike you are right… I forgot about custom code in afterFind event. This code should be used only for backoffice… Thank you both, issue solved then.