does gii automatically create relations for generated models?

牧云@^-^@ 提交于 2019-12-19 10:44:20

问题


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,


回答1:


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)



回答2:


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.



来源:https://stackoverflow.com/questions/9164733/does-gii-automatically-create-relations-for-generated-models

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!