Models : Listings and Auctions
关系: Auctions BELONGS_TO Listings
Listings PK : id
Auctions FK : Listings_id
问题: 如果(保存期间连接缓慢/丢失)列表 PK 和 Auction ,我如何在我的 VIEW 中获取两个表的所有属性(对象) 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 ....
我收到了这个错误
试图获取非对象的属性