Answer the question
In order to leave comments, you need to log in
How to properly organize relationships between tables?
Hello. I got tired with the table links in Yii 1. I can't get the data correctly in any way.
I have 2 tables:
1 table of warehouses, there are id, name, city_id
And in fact, using the city_id field, I should get the name of the city from the table with cities.
I organize communication in the City model
'stockInCity' => array(self::HAS_MANY, 'Stock', 'city_id'),
$a = City::model()->with('stockInCity')->findByPk(1250);
echo "<pre>"; print_r($a); echo "</pre>";
'stockInCity' => array(self::HAS_MANY, 'City', 'id'),
but the output is an empty object. Answer the question
In order to leave comments, you need to log in
If you need to get City from Stock, then you need to specify in Stock
PS It is more correct to call not "stockInCity", but "stocks"
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question