Php Yii关系数据库不工作
我的UsersController上有这段代码Php Yii关系数据库不工作,php,yii,Php,Yii,我的UsersController上有这段代码 $userModel = Users::model()->with('userSubscriptionTypes')->find(array( 'order'=>'userSubscriptionTypes.idUserSubscriptionType DESC', 'limit'=>1, 'condition'=>'t.paypal_profil
$userModel = Users::model()->with('userSubscriptionTypes')->find(array(
'order'=>'userSubscriptionTypes.idUserSubscriptionType DESC',
'limit'=>1,
'condition'=>'t.paypal_profile_id=:paypal_profile_id',
'params'=>array(':paypal_profile_id'=>'I-S09AAFCLHH57')
));
这给了我一个错误:
CDbCommand failed to execute the SQL statement: SQLSTATE[42S22]: Column not found: 1054 Unknown column 'userSubscriptionTypes.idUserSubscriptionType' in 'order clause'. The SQL statement executed was: SELECT `t`.`idUser` AS `t0_c0`, `t`.`username` AS `t0_c1`, `t`.`password` AS `t0_c2`, `t`.`email_address` AS `t0_c3`, `t`.`firstname` AS `t0_c4`, `t`.`lastname` AS `t0_c5`, `t`.`isAdmin` AS `t0_c6`, `t`.`paypal_profile_id` AS `t0_c7`, `t`.`date_created` AS `t0_c8` FROM `users` `t` WHERE (t.paypal_profile_id=:paypal_profile_id) ORDER BY userSubscriptionTypes.idUserSubscriptionType DESC LIMIT 1
根据错误给出的SQL代码片段,带的似乎不起作用
这是Users.php
关系模型代码:
public function relations()
{
// NOTE: you may need to adjust the relation name and the related
// class name for the relations automatically generated below.
return array(
'trackedItems' => array(self::HAS_MANY, 'TrackedItems', 'idUser'),
'userSubscriptionTypes' => array(self::HAS_MANY, 'UserSubscriptionType', 'idUser'),
);
}
这个怎么了?还有想法
谢谢 对于order子句,只需尝试使用'order'=>'idUserSubscriptionType DESC'
。并确保在所选表中有列idUserSubscriptionType
。实际上,我已经尝试了该列,但仍然存在该错误。您可以通过输出来检查查询吗?这是正在输出的查询:选择t
idUser
作为t0\uc0
,t
username
ASt0\u c1
,t
password
ASt0\u c2
,t
email\u address
ASt0\u c3
,t
firstnameASt0\u c4
,t
,t
isAdmin
ASt0\u c6
,t
paypal\u profile\u id
ASt0\u c7
,t
创建日期t0\u c8
来自用户t
其中(t.paypal\u profile\u id=:paypal\u profile\u id)ORDER BY userSubscriptionTypes.idUserSubscriptionType DESC LIMIT 1idUserSubscriptionType
此列位于哪个表中?