Warning: file_get_contents(/data/phpspider/zhask/data//catemap/1/php/276.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Php Yii关系数据库不工作_Php_Yii - Fatal编程技术网

Php Yii关系数据库不工作

Php Yii关系数据库不工作,php,yii,Php,Yii,我的UsersController上有这段代码 $userModel = Users::model()->with('userSubscriptionTypes')->find(array( 'order'=>'userSubscriptionTypes.idUserSubscriptionType DESC', 'limit'=>1, 'condition'=>'t.paypal_profil

我的UsersController上有这段代码

$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
AS
t0\u c1
t
password
AS
t0\u c2
t
email\u address
AS
t0\u c3
t
firstnameAS
t0\u c4
t
t
isAdmin
AS
t0\u c6
t
paypal\u profile\u id
AS
t0\u c7
t
创建日期
t0\u c8
来自
用户
t
其中(t.paypal\u profile\u id=:paypal\u profile\u id)ORDER BY userSubscriptionTypes.idUserSubscriptionType DESC LIMIT 1
idUserSubscriptionType
此列位于哪个表中?