Harsha Tharanga
Harsha Tharanga

Reputation: 94

YII Criteria 'With' relation issue

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

CDbCommand failed to execute the SQL statement: SQLSTATE[42000]: Syntax error or access violation: 1066 Not unique table/alias: 'user'. The SQL statement executed was: SELECT t.id AS t0_c0, t.`grn ......

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


    );

please help me to solve this...

Upvotes: 1

Views: 4034

Answers (1)

Michael
Michael

Reputation: 43

You should specify an alias for either (or both) of the relationships like this:

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

Upvotes: 2

Related Questions