Answer the question
In order to leave comments, you need to log in
Why is a relation in Yii treated as a non-existent property?
Hey!
I have 2 tables:
t_product (CODE[ int ], NAME) - derived class Product
l_order_22_product (CODE, PRODUCT_CODE[ int ], COUNT[ int ]) - LOrder22Product
class
In the LOrder22Product class, the links are written:
public function relations()
{
return array(
'product' => array(self::BELONGS_TO, 'Product', 'PRODUCT_CODE'),
'orders' => array(self::BELONGS_TO, 'Orders', 'ORDER_CODE'),
);
}
$mod = LOrder22Product::model()->findByPk(13);
echo $mod->product->NAME;
Answer the question
In order to leave comments, you need to log in
Yii picks up connected models very well if foreign keys are affixed to the corresponding tables. Have you set up foreign keys?
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question