首页
学习
活动
专区
圈层
工具
发布
首页
学习
活动
专区
圈层
工具
MCP广场
社区首页 >问答首页 >Yii模型->findAll(),如何添加关系表列?

Yii模型->findAll(),如何添加关系表列?
EN

Stack Overflow用户
提问于 2014-09-15 10:52:04
回答 1查看 1.8K关注 0票数 0

我有两个模特。他们是DisnotificationUpdate和DisNotification。DisnotificationUpdate关系如下。

代码语言:javascript
运行
复制
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'),

        );
    }

它的属性如下。

代码语言:javascript
运行
复制
public function attributeLabels()
    {
        return array(
            'id' => 'ID',
            'notifi_id' => 'Notifi',
            'view' => 'View',
            'userid' => 'Userid',
        );
    }

Disnotification模型具有以下属性。

代码语言:javascript
运行
复制
public function attributeLabels()
    {
        return array(
            'id' => 'ID',
            'notification' => 'Notification',
            'owner' => 'Owner',
            'workspace_id' => 'Workspace',
            'postID' => 'Post',
            'pDate' => 'P Date',
        );
    }

我希望从DisnotificationUpdate中选择值,并在DisNotification中使用'pDate‘按值排序。我试过如下。

代码语言:javascript
运行
复制
 $dataProvider=DisnotificationUpdate::model()->findAll(array(
        'condition' => 'userid=:userid',
        'order' => 'notifi.pDate ASC',
        'limit'=>10,
        'params' => array(':userid' => $myid)
    ));

但它在“order子句”中出现了一个错误,即“未知列'notifi.pDate‘”。我做错什么了?谢谢。

EN

回答 1

Stack Overflow用户

回答已采纳

发布于 2014-09-15 11:25:02

您需要急切地加载相关模型。

代码语言:javascript
运行
复制
$dataProvider=DisnotificationUpdate::model()->findAll(array(
    'with' => array('notifi'),
    'condition' => 'userid=:userid',
    'order' => 'notifi.pDate ASC',
    'limit'=>10,
    'params' => array(':userid' => $myid)
));
票数 3
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/25846396

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档