Reputation: 2610
I have a problem with populateRelation, lets explain, that we have some Article, this Article can have tags, so we do another table article_tag, this do ArticleTag object in propel, lets find the all Articles
$Articles = ArticleQuery::create()->find();
okey so we have now all Articles, now we wanna have all of those tags for each Article, so here we go:
$Articles->populateRelation('ArticleTag');
and then is some view we do:
foreach($Articles as $Article) {
// some stuff
foreach($Article->getArticleTags() as $ArticleTag) { // this should not do query!
// some additional stuff
}
}
and when I have 1 200 articles in db, with populateRelation the queries going down up to 600, but should be only 2, for articles and for articles tags.
Where I do mistake?
Upvotes: 1
Views: 1851
Reputation: 22756
I put an answer here about recursively populate related objects.
You just have to explicit joinWith
the table in your query:
$articles = ArticleQuery::create()->joinWith('Article.ArticleTag')->find();
// this won't perform others queries
// not sure about getArticleTags or getArticleTag
foreach($articles->getArticleTags() as $ArticleTag) { }
Upvotes: 3