1

モデル: リストとオークション
リレーション: オークション BELONGS_TO リスト
リスト PK : id
オークション FK : Listings_id

問題: リスト PK とオークションの場合 (保存中に接続が遅い/失われた場合)、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 ....

このエラーが発生しました

非オブジェクトのプロパティを取得しようとしています

4

0 に答える 0