多表查询求助!!! [ 新手入门 ]
三个表 [Product]--[userproduct]--[User]
[Product]为物品信息,包含作者uid字段 [user-product]为用户对物品的操作统计,如顶、踩、喜欢 [User]为用户表
现在要分页显示用户喜欢的物品,高手帮帮忙!
我的代码
User 模型加了 'likes'=>array( self::MANY_MANY, 'Product', '{{userproduct}}( uid, pid )')
执行
$uid = (int)( $_GET['uid'] );
$user = User::model()->findByPk( $uid );
if( $user ){
print_r($user->likes);
}
时报错
CDbCommand failed to execute the SQL statement: SQLSTATE[42S22]: Column not found: 1054 Unknown column 'likes_likes. uid' in 'on clause'. The SQL statement executed was: SELECT `likes`.`pid` AS `t1_c0`, `likes`.`uid` AS `t1_c1`, `likes`.`title` AS `t1_c2`, `likes`.`price` AS `t1_c3`, `likes`.`poster` AS `t1_c4`, `likes`.`thumb_poster` AS `t1_c5`, `likes`.`tiny_poster` AS `t1_c6`, `likes`.`postdate` AS `t1_c7`, `likes`.`isshow` AS `t1_c8`, `likes`.`catalog_id` AS `t1_c9`, `likes`.`description` AS `t1_c10`, `likes`.`type` AS `t1_c11` FROM `buyinfo_product` `likes` INNER JOIN `buyinfo_userproduct` `likes_likes` ON (`likes_likes`.` uid`=:ypl0) AND (`likes`.`pid`=`likes_likes`.`pid `)
怎么办?
共 4 条回复
-
建议你看下这个,http://www.yiichina.com/doc/guide/1.1/database.arr
貌似你的relation写的有问题
Ceelog
注册时间:2011-11-25
最后登录:1970-01-01
在线时长:0小时0分
最后登录:1970-01-01
在线时长:0小时0分
- 粉丝0
- 金钱20
- 威望0
- 积分20