in real words.. i have restaurant model, restaurant model have many foods, and each food have one category,
so m question is how to get all used categories through restaurant model
Really Thanks.
Look at http://www.yiiframework.com/doc/guide/1.1/en/database.arr#relational-query-with-through
Something like:
public function relations()
{
return array(
'foods' => array(self::HAS_MANY, 'Food', 'restaurant_id'),
'categories' => array(self::HAS_MANY, 'Category', array('category_id'=>'id'),
'through' => 'foods'),
);
}
Should be in your Restaurant
model.
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.