0

我的 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 代码片段,这似乎with不起作用。

这是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'),
        );
}

这个有什么问题?和想法?

谢谢!

4

0 回答 0