Answer the question
In order to leave comments, you need to log in
How can a relationship be described in Yii 1.x through a relationship?
For example, we have 3 models Category Object File
Category describes the relationship (object_category is a link table):
public function relations()
{
return array(
'rel_object'=>array(
self::MANY_MANY,
'Object',
'object_category(n_id, o_id)'
)
);
}
public function relations()
{
return array(
'rel_file'=>array(
self::HAS_MANY,
'File',
'',
'on'=>"rel_file.owner_id=t.id AND rel_file.type='gallery'"
)
);
}
$result = Object::model()->with('rel_file')->findByPk(1);
print_r($result->rel_file);
$result = Category::model()->with('rel_object')->findByPk(1);
foreach ($result->rel_object AS $object) {
print_r($object->rel_file);
}
Answer the question
In order to leave comments, you need to log in
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question