Yii - 检查模型关系

时间:2013-07-15 10:17:36

标签: php yii relation

模特:列表和拍卖
关系:拍卖BELONGS_TO列表
清单PK :id
拍卖FK :listings_id

问题:如果(保存期间连接速度慢/丢失),我如何获取两个表中的所有属性(对象)列表PK和Auction FK不相同。
<登记/> 模型(拍卖)

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(
        'listings' => array(self::BELONGS_TO, 'Listings', 'listing_id'),
    );

}

控制器

$randomListing= new RandomListingGenerator();
$randomListing=$randomListing->actionGenerate();
$profile=new Profile;
            $this->render('index', array(
                'data' => $randomListing,   
            ));

随机列表生成器

class RandomListingGenerator{
    public function actionGenerate(){
$criteria = new CDbCriteria();
        $criteria->select = '*, RAND() as rand';
        $criteria->order = 'rand';
        $criteria->limit = 1;
        $criteria->together = true;
        $criteria->with=array(
                'listings'=>array('select'=>'id'),
        );

        return $randomListing = Auctions::model()->find($criteria);
 }

}

查看

echo $data->listings->rooms; 
//other attributes ....

我收到了这个错误

尝试获取非对象的属性

0 个答案:

没有答案