Hey Guys,
I’ve run into an issue with relations. I have to models with relations:
GGame:
/**
* @return array relational rules.
*/
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(
'thumbnail'=>array(self::HAS_MANY, 'GPictures', 'game_id',
'condition'=>"thumbnail.name='thumbnail'",
)
);
}
and GPictures:
/**
* @return array relational rules.
*/
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(
'game'=>array(self::BELONGS_TO, 'GGame', 'game_id')
);
}
now I do a query on GGame like this:
$criteria = new CDbCriteria;
$criteria->limit = 10;
$criteria->order = 'id DESC';
$items = GGame::model()->with('thumbnail')->findAll($criteria);
if I do a dump: <?php echo "<pre>"; var_dump($items[4]->thumbnail); echo "</pre>";?>
I can see that the model is loaded together with the thumbnail image:
["_new":"CActiveRecord":private]=>
bool(false)
["_attributes":"CActiveRecord":private]=>
array(4) {
["id"]=>
string(2) "15"
["name"]=>
string(9) "thumbnail"
["type"]=>
string(4) ".jpg"
["game_id"]=>
string(2) "16"
}
but if I print out: <?php echo "<pre>"; var_dump($items[4]->thumbnail->name); echo "</pre>";?>
or any other field from the GPictures table it always is set to NULL.
Anyone got an idea what I am doing wrong here?
Any help is appreciated!
Thanks in advance!
Seb