简体   繁体   English

如何在Yii 1.1中更改默认别名?

[英]How to change default alias name in Yii 1.1?

I have joined with two table by using model association. 我已经通过使用模型关联加入了两个表。 This two tables are films and movie_streams But there is some error 这两个表是filmsfilms movie_streams但是有一些错误

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: Film.php模型:

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 对于filmst和对于movie_streamst0

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. 通过指定关系的alias属性,可以避免表别名冲突。

$comments = Comment::model()->with(array(
     'author',
     'post',
     'post.author' => array('alias' => 'p_author'))
   )->findAll();

use 采用

model_name.feild_name 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 通过使用allias避免表冲突

$comments=Comment::model()->with(array(
 'author',
  'post',
  'post.author'=>array('alias'=>'p_author')))->findAll(array(
   'order'=>'author.name, p_author.name, post.title'
 ));

, more details here 更多详细信息在这里

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM