Recently decided to move from Zend to Yii, a problem with CActiveDataProvider, namely the use of related tables.
There are three tables, posts, posts_topics, topics (the standard model of tag many to many)
Must withdraw all posts on a given topic (tag)
$dataProvider = new CActiveDataProvider('Post', array(
'criteria' => array(
'condition' => 'topics.seo = :seo',
'params' => array(':seo' => $_GET['topic_url']),
'with' => array('topics'),
'order' => 'update_time DESC'
),
'pagination' => array(
'pageSize' => Yii::app()->params['postsPerPage'],
),
));
And judging by the documentation is correct.
But the derivation of an error “Column not found: 1054 Unknown column ‘topics.seo’ in ‘where clause’”
I saw the log and see two queries:
first (which incidentally works and built correctly)
SELECT
COUNT(DISTINCT `t`.`id`)
FROM `posts` `t`
LEFT OUTER JOIN `posts_topics` `topics_topics`
ON (`t`.`id` = `topics_topics`.`post_id`)
LEFT OUTER JOIN `topics` `topics`
ON (`topics`.`id` = `topics_topics`.`topic_id`)
WHERE (topics.seo = :seo)
and second (which throws out an exception)
SELECT
`t`.`id` AS `t0_c0`,
`t`.`title` AS `t0_c1`,
`t`.`content` AS `t0_c2`,
`t`.`create_time` AS `t0_c3`,
`t`.`update_time` AS `t0_c4`,
`t`.`author_id` AS `t0_c5`,
`t`.`seo` AS `t0_c6`
FROM `posts` `t`
WHERE (topics.seo = :seo)
ORDER BY update_time DESC
LIMIT 15)
Why does the second query is not related tables?
I am Russian, sorry for bad english.