Model Relationships

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?

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

Thanks for the tip on InnoDB+foreign key constraints, that works perfectly :slight_smile: