I have joined with two table by using model association. This two tables are films
and movie_streams
But there is some error
My Query:
$film = Film::model()->with('movie_streams')->find(array('select' => '*', 'condition' => 'user_id=:user_id, 'params' => array(':user_id' => $user_id)));
Film.php model:
public function relations() {
return array(
'movie_streams' => array(self::HAS_MANY, 'MovieStream','movie_id'),
);
}
Error Message:
CDbCommand failed to execute the SQL statement: SQLSTATE[23000]: Integrity constraint violation: 1052 Column 'user_id' in where clause is ambiguous
I saw by default taking alias name. For films
table t
and for movie_streams
table t0
How to set manual alias what I want for my above two tables?
You can avoid the collision of tables aliases by specifying the alias property of the relation.
$comments = Comment::model()->with(array(
'author',
'post',
'post.author' => array('alias' => 'p_author'))
)->findAll();
use
model_name.feild_name
$film = Film::model()->with('movie_streams')->find(array('select' => '*', 'condition' => 'film.user_id=:user_id, 'params' => array(':user_id' => $user_id)));
or
avoid collision of table by using allias
$comments=Comment::model()->with(array(
'author',
'post',
'post.author'=>array('alias'=>'p_author')))->findAll(array(
'order'=>'author.name, p_author.name, post.title'
));
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.