Salam(Hi), How I can prevent from loading related model(child) for a (parent) model?
Asked
Active
Viewed 222 times
0
-
No one can help?! My problem is the true yet!! – Masoud Nazari Jun 25 '13 at 08:03
1 Answers
0
How do you know they are loaded with parent model? Have you checked the LogRoute? (Uncomment it in the config)
'log' => array(
'class' => 'CLogRouter',
'routes' => array(
...
array(
'class' => 'CWebLogRoute',
'categories' => 'system.db.*',
'except' => 'system.db.ar.*',
),
Related models are not loaded by default (if you haven't used with('relatedModel')
method).
Any related records will be lazy loaded when accessing the relation property the first time. http://www.yiiframework.com/forum/index.php/topic/7430-lazy-loading-of-many-many-relations/page_view_findpost_p_37674

robert.little
- 410
- 3
- 13
-
-
2. Have checked the LogRoute and I see the child models query executed for each parent model!!! – Masoud Nazari Jun 23 '13 at 10:18
-
in that case it's lazy loading... Probably you are accessing the relation property that is not loaded. Or? – robert.little Jun 23 '13 at 10:25
-
this is my code: ParentModel::model()->findAll(); and it run 7 queries. 3 for ParentModel and 4 for relatedModel! – Masoud Nazari Jun 23 '13 at 11:55
-
-
no, I put an exit() after that code (for test) and no view rendered!! – Masoud Nazari Jun 23 '13 at 12:35