When I use AR model , the exception :
public function actionDetail(){
$userId = Yii::app()->request->getQuery('user_id', 1);
$callback = Yii::app()->request->getQuery('callback');
$criteria = new CDbCriteria();
$criteria->compare('id', $userId);
$criteria->with = array('beer2014Albums', 'beer2014Pics');
$user = Beer2014Users::model()->find($criteria);
$result = CJSON::encode($user);
if (isset($callback) && !empty($callback)) {
echo $callback . "($result)";
} else {
echo $result;
}
}
when I access the action, the errors:
CDbCommand failed to execute the SQL statement: SQLSTATE[23000]: Integrity constraint violation: 1052 Column ‘id’ in where clause is ambiguous. The SQL statement executed was: SELECT t
.id
AS t0_c0
, t
.username
AS t0_c1
, t
.sex
AS t0_c2
, t
.idcard
AS t0_c3
, t
.phone
AS t0_c4
, t
.mobile
AS t0_c5
, t
.nationality
AS t0_c6
, t
.ipaddr
AS t0_c7
, t
.province
AS t0_c8
, t
.city
AS t0_c9
, t
.area
AS t0_c10
, t
.town
AS t0_c11
, t
.height
AS t0_c12
, t
.weight
AS t0_c13
, t
.bwh
AS t0_c14
, t
.announce
AS t0_c15
, t
.email
AS t0_c16
, t
.hobby
AS t0_c17
, t
.intro_myself
AS t0_c18
, t
.wb_uid
AS t0_c19
, t
.wb_nickname
AS t0_c20
, t
.status
AS t0_c21
, t
.school_name
AS t0_c22
, t
.address
AS t0_c23
, t
.job
AS t0_c24
, t
.salary
AS t0_c25
, t
.company
AS t0_c26
, t
.company_addr
AS t0_c27
, t
.zip
AS t0_c28
, t
.create_time
AS t0_c29
, t
.update_time
AS t0_c30
, t
.b1
AS t0_c31
, t
.b2
AS t0_c32
, beer2014Albums
.id
AS t1_c0
, beer2014Albums
.user_id
AS t1_c1
, beer2014Albums
.name
AS t1_c2
, beer2014Albums
.first_pic_url
AS t1_c3
, beer2014Albums
.vote_num
AS t1_c4
, beer2014Albums
.create_time
AS t1_c5
, beer2014Albums
.update_time
AS t1_c6
, beer2014Albums
.status
AS t1_c7
, beer2014Albums
.b1
AS t1_c8
, beer2014Albums
.b2
AS t1_c9
, beer2014Pics
.id
AS t2_c0
, beer2014Pics
.user_id
AS t2_c1
, beer2014Pics
.albums_id
AS t2_c2
, beer2014Pics
.pic_url
AS t2_c3
, beer2014Pics
.description
AS t2_c4
, beer2014Pics
.link
AS t2_c5
, beer2014Pics
.vote_num
AS t2_c6
, beer2014Pics
.status
AS t2_c7
, beer2014Pics
.create_time
AS t2_c8
, beer2014Pics
.update_time
AS t2_c9
, beer2014Pics
.b1
AS t2_c10
, beer2014Pics
.b2
AS t2_c11
FROM tbl_beer2014_users
t
LEFT OUTER JOIN tbl_beer2014_albums
beer2014Albums
ON (beer2014Albums
.user_id
=t
.id
) LEFT OUTER JOIN tbl_beer2014_pics
beer2014Pics
ON (beer2014Pics
.user_id
=t
.id
) WHERE (id=:ycp0)
the SQL is generated by yii, in where: WHERE(id=:ycp0),this id is ambiguous, how can I do? any help?