物业" CHasOneRelation.limit"未定义

时间:2015-06-19 08:19:35

标签: php database yii

如何摆脱此错误:Property "CHasOneRelation.limit" is not defined.

这是我的关系方法:

public function relations()
    {
        return array(
            'documents' => array(self::HAS_MANY, 'Document', 'dossier_id',),
            'lastLogline' => array(
                self::HAS_ONE, 
                'Logline ll', 
                'dossier_id',
                'limit'              => 1,
                'order'              => 'll.create_date DESC'),
            'lastmodifiedUser'   => array(self::HAS_ONE, 'User', 'lastmodified_user_id',),
            'loglines' => array(self::HAS_MANY, 'Logline', 'dossier_id',),
            'priority' => array(self::HAS_ONE, 'Priority', 'priority_id',),
            'properties' => array(self::MANY_MANY, 'Property', 'doe_dossier_has_property(dossier_id,property_id)',),
            'state' => array(
                self::HAS_ONE,
                'State',
                'doe_logline(dossier_id,state_id) ll',
                'limit'  => 1,
                'order'  => 'll.create_date DESC'),
        );
    }

然后当我进入我的网页时,我得到了以下错误:

    /vagrant/vendor/yiisoft/yii/framework/db/ar/CActiveRecord.php(2011)

1999      * Constructor.
2000      * @param string $name name of the relation
2001      * @param string $className name of the related active record class
2002      * @param string $foreignKey foreign key for this relation
2003      * @param array $options additional options (name=>value). The keys must be the property names of this class.
2004      */
2005     public function __construct($name,$className,$foreignKey,$options=array())
2006     {
2007         $this->name=$name;
2008         $this->className=$className;
2009         $this->foreignKey=$foreignKey;
2010         foreach($options as $name=>$value)
2011             $this->$name=$value;
2012     }
2013 
2014     /**
2015      * Merges this relation with a criteria specified dynamically.
2016      * @param array $criteria the dynamically specified criteria
2017      * @param boolean $fromScope whether the criteria to be merged is from scopes
2018      */
2019     public function mergeWith($criteria,$fromScope=false)
2020     {
2021         if($criteria instanceof CDbCriteria)
2022             $criteria=$criteria->toArray();
2023         if(isset($criteria['select']) && $this->select!==$criteria['select'])

如何才能解决这个问题?

当我在网上搜索时,我发现了one,还有one,但这对我没有帮助。

1 个答案:

答案 0 :(得分:1)

你不能限制有一个关系,因为你已经说过HAS_ONE。 CHasOneRelation现在知道需要找到一条相关记录。

limit仅用于主查询以声明所需的行数。

不要将表别名放在:' Logline ll' ,.别名是lastLogline(数组定义)。