I have 3 tables:
- numbers (id, name)
- food (id, name)
- numbers_food (number_id, food_id, price_per_ad, price_per_ch)
How I can to get a price_per_ad and price_per_ch data for each food_id from numbers_food relationship table?
I have 3 tables:
How I can to get a price_per_ad and price_per_ch data for each food_id from numbers_food relationship table?
Just define relationships in models.
In NumberFoodModel:
'food' => array(self::BELONGS_TO, 'Food', 'food_id'),
In FoodModel:
'number_food' => array(self::HAS_MANY, 'NumberFood', 'food_id'),
Now in your code just use
Food::model()->with('number_food')->findByPk($id)