YII标准'与'关系问题

时间:2013-08-27 06:46:43

标签: activerecord yii criteria

WHEN IAM TRYING TO GET invoice created user and grn created user i am getting this error...
  

CDbCommand无法执行SQL语句:SQLSTATE [42000]:   语法错误或访问冲突:1066不唯一的表/别名:'user'。   执行的SQL语句是:SELECT tid AS t0_c0t。`grn ......

 $criteria->with = array(
                "invoice.user" => array('select' => 'display_name'),
                "grn.user" => array(
                    'select' => 'display_name',
                ),


    );

请帮我解决这个问题......

1 个答案:

答案 0 :(得分:2)

您应该为这两种关系指定一个别名,如下所示:

$criteria->with = array(
  "invoice.user" => array(
    'alias' => 'invoiceUser', 
    'select' => 'display_name'
  ),
  "grn.user" => array(
    'alias' => 'grnUser',
    'select' => 'display_name',
  ),
);