本文介绍了gii 会自动为生成的模型创建关系吗?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我是 Yii 的新手.在文档中,似乎暗示 gii 将为相关模型创建关系.但是当使用gii从DB生成模型时,情况似乎并非如此.例如,我有一个用户表和一个配置文件表,其中有一列user_id INTEGER DEFAULT 0",但在生成的模型中,关系数组为空.我做错了什么,还是gii不能自动识别这些关系?谢谢,

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,

推荐答案

如果您在引用列的注释中包含如下格式,Gii 将为 MyISAM 表创建关系:

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)

这篇关于gii 会自动为生成的模型创建关系吗?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!

06-26 16:04