models: listings , auctions
relation: auctions belongs_to listings
listings pk: id
auctions fk: listings_id
problem: how can attributes(objects) of both tables in view if(slow/lost connection during save) listings pk , auction fk not same.
model(auctions)
public function relations() { // note: may need adjust relation name , related // class name relations automatically generated below. return array( 'listings' => array(self::belongs_to, 'listings', 'listing_id'), ); }
controller
$randomlisting= new randomlistinggenerator(); $randomlisting=$randomlisting->actiongenerate(); $profile=new profile; $this->render('index', array( 'data' => $randomlisting, ));
random listing generator
class randomlistinggenerator{ public function actiongenerate(){ $criteria = new cdbcriteria(); $criteria->select = '*, rand() rand'; $criteria->order = 'rand'; $criteria->limit = 1; $criteria->together = true; $criteria->with=array( 'listings'=>array('select'=>'id'), ); return $randomlisting = auctions::model()->find($criteria); }
}
view
echo $data->listings->rooms; //other attributes ....
i got error
trying property of non-object
Comments
Post a Comment