Yii Related query problem
Three sheet A B C
AB is a pair of multiple
BC is a one-to
How to query a record that satisfies the final display of C
------Solution--------------------
A---User table (with user_name field)
B---Article table (with user_id field)
C---article_content table (with article_content_id field)
Condition: Query user's username through the article_content_id field of the Article_content table
Requires two relation, add one to the model/comment.php:
Public Function relations () {
Return Array (
....
' UserInfo ' = Array (self::belogns_to, ' User ', ' user_id '),
);
}
Ibid., add in model/commentcontent.php:
' Article ' = = Array (self::has_one, ' article ', ' article_content_id '),
Inquire:
$result = Articlecontent::model (), find (' article_content_id =: aid ', Array (': aid ' = $articleId));
Prinr_r ($result-attributes); The fields of the Article_content table are all printed.
Print_r (attributes, article, $result); Get the fields of the article table
Print_r (user_name, UserInfo, article, $result); Get username
I am purely in order to construct the landlord said this kind of situation is written like this, generally should not be designed so, many are related fields are in that intermediate table, article, check the time is through the article model related to other tables query it