Есть модель TblOrder
Код: Выделить всё
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(
'tbl_product_order' => array(self::HAS_MANY, 'TblProductOrder', 'id_order') ,
'product' => array(self::HAS_ONE, 'TblProduct', 'id_product'),
);
}
Код: Выделить всё
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(
'product' => array(self::HAS_ONE, 'TblProduct', 'id_product'),
);
}
Модель TblOrder по id_order связана с моделью TblProductOrder, т.е. таблица заказов -> таблица товаров заказов
Модель TblProductOrder в свою очередь связана с моделью TblProduct по ключу product, т.е. таблица товаров (каждая позиция) -> 1 товар таблицы TblProduct
действия типа
Код: Выделить всё
$model = TblOrders::model()->with('tbl_product_order.product')->findAll();
Вопрос как перебирая
Код: Выделить всё
$TblProductOrder = TblOrders::model()->findByPk($id)->tbl_product_order;