我使用模型关联加入了两个表。这两个表格为<div class="header">
<div id="logo">
<img src="http://placehold.it/200x100">
</div>
<div class="navbar">
<div id="leftnavbar">
<ul>
<li><span id="dollarydoos">Dollarydoos:</span> <span id="dosh">1.00000000</span> <span id="dsh">DSH</span></li>
</ul>
</div>
<div id="rightnavbar">
<ul>
<li><a href="index.html">Button1</a></li>
<li><a href="index.html">Button2</a></li>
<li><a href="index.html">Button3</a></li>
<li><a href="index.html">Button4</a></li>
</ul>
</div>
</div>
</div>
和films
但是有一些错误
我的查询:
movie_streams
Film.php模型:
$film = Film::model()->with('movie_streams')->find(array('select' => '*', 'condition' => 'user_id=:user_id, 'params' => array(':user_id' => $user_id)));
错误讯息:
public function relations() {
return array(
'movie_streams' => array(self::HAS_MANY, 'MovieStream','movie_id'),
);
}
我默认看到了别名。对于CDbCommand failed to execute the SQL statement: SQLSTATE[23000]: Integrity constraint violation: 1052 Column 'user_id' in where clause is ambiguous
表films
和t
表movie_streams
如何为上面两个表设置手动别名我想要的内容?
答案 0 :(得分:0)
您可以通过指定关系的别名属性来避免表别名的冲突。
$comments = Comment::model()->with(array(
'author',
'post',
'post.author' => array('alias' => 'p_author'))
)->findAll();
答案 1 :(得分:0)
使用
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)));
或
使用allias
避免表冲突$comments=Comment::model()->with(array(
'author',
'post',
'post.author'=>array('alias'=>'p_author')))->findAll(array(
'order'=>'author.name, p_author.name, post.title'
));