我有两个模特。他们是DisnotificationUpdate和DisNotification。DisnotificationUpdate关系如下。
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(
'user' => array(self::BELONGS_TO, 'Login', 'userid'),
'notifi' => array(self::BELONGS_TO, 'Disnotification', 'notifi_id'),
);
}
它的属性如下。
public function attributeLabels()
{
return array(
'id' => 'ID',
'notifi_id' => 'Notifi',
'view' => 'View',
'userid' => 'Userid',
);
}
Disnotification模型具有以下属性。
public function attributeLabels()
{
return array(
'id' => 'ID',
'notification' => 'Notification',
'owner' => 'Owner',
'workspace_id' => 'Workspace',
'postID' => 'Post',
'pDate' => 'P Date',
);
}
我希望从DisnotificationUpdate中选择值,并在DisNotification中使用'pDate‘按值排序。我试过如下。
$dataProvider=DisnotificationUpdate::model()->findAll(array(
'condition' => 'userid=:userid',
'order' => 'notifi.pDate ASC',
'limit'=>10,
'params' => array(':userid' => $myid)
));
但它在“order子句”中出现了一个错误,即“未知列'notifi.pDate‘”。我做错什么了?谢谢。
发布于 2014-09-15 11:25:02
您需要急切地加载相关模型。
$dataProvider=DisnotificationUpdate::model()->findAll(array(
'with' => array('notifi'),
'condition' => 'userid=:userid',
'order' => 'notifi.pDate ASC',
'limit'=>10,
'params' => array(':userid' => $myid)
));
https://stackoverflow.com/questions/25846396
复制相似问题