I haven't seen anyone really address the proper way in Yii to build relationships between models, automatically, when using yiic to create your model classes.
It seems that Yii should be able to automatically detect that a column named "user_id" in the "posts" table, would relate to the "users" table's "id" column, but in practice, the only time I've had yiic actually build in model relationships, is when there is a composite key in a table.
Are there no conventions in place for Yii to be able to auto-detect relations when building models?
Additionally, the composite key support in v1.1 is lacking for CRUD generation, which sucks, as it existed for v1.0?
Page 1 of 1
Model Relationships How to auto-build model relationships?
#1
Posted 08 February 2010 - 11:31 AM
Need live Yii support? - Join the #yii IRC channel on Freenode!
#2
Posted 08 February 2010 - 03:24 PM
intel352, on 08 February 2010 - 11:31 AM, said:
I haven't seen anyone really address the proper way in Yii to build relationships between models, automatically, when using yiic to create your model classes.
It seems that Yii should be able to automatically detect that a column named "user_id" in the "posts" table, would relate to the "users" table's "id" column, but in practice, the only time I've had yiic actually build in model relationships, is when there is a composite key in a table.
Are there no conventions in place for Yii to be able to auto-detect relations when building models?
Additionally, the composite key support in v1.1 is lacking for CRUD generation, which sucks, as it existed for v1.0?
It seems that Yii should be able to automatically detect that a column named "user_id" in the "posts" table, would relate to the "users" table's "id" column, but in practice, the only time I've had yiic actually build in model relationships, is when there is a composite key in a table.
Are there no conventions in place for Yii to be able to auto-detect relations when building models?
Additionally, the composite key support in v1.1 is lacking for CRUD generation, which sucks, as it existed for v1.0?
If you use innodb tables and add constraints, yiic will generate your models with the relationships accordingly. I think i've also seen where you can specify relationships in table comments for your mysiam tables and yiic will also generate your relationships
php:
foreach(array('cat', 'dog', 'cow') as $animal) echo $animal."\n";
python:
[(animal, print(animal)) for animal in ['cat', 'dog', 'cow']]
ruby:
['cat', 'dog', 'cow'].each {|animal| puts animal}
You say Tomato, I say Tomato.
#3
Posted 09 February 2010 - 10:50 AM
Thanks for the tip on InnoDB+foreign key constraints, that works perfectly :-)
Need live Yii support? - Join the #yii IRC channel on Freenode!
Share this topic:
Page 1 of 1

Help












