does gii automatically create relations for genera

2019-02-20 18:19发布

I'm new to Yii here. In the documentation, it seems to imply that gii will create the relations for related models. But when using gii to generate models from DB, it doesn't seem to be the case. For example, I have a user table and a profile table with a column "user_id INTEGER DEFAULT 0", but the relations array is empty in the generated model. Did I do something wrong, or gii just doesn't automatically recognize the relations? Thanks,

标签: yii gii
2条回答
霸刀☆藐视天下
2楼-- · 2019-02-20 18:54

Gii can automatically create relations for generated models if corresponding tables in your DB have foreign keys, but not all storage engines support foreign keys. For example, if you use MyISAM tables in MySQL, you have no way to define it.

查看更多
我命由我不由天
3楼-- · 2019-02-20 19:04

Gii will create relations for MyISAM tables if you include a format like the following in the comment of the referenced columns:

CONSTRAINT FOREIGN KEY (name_of_this_field) REFERENCES related_table_name(related_field_name)
查看更多
登录 后发表回答