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,
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
如果您在引用列的注释中包含如下格式,Gii 将为 MyISAM 表创建关系:
Gii will create relations for MyISAM tables if you include a format like the following in the comment of the referenced columns:
如果数据库中的相应表具有外键,Gii 可以自动为生成的模型创建关系,但并非所有存储引擎都支持外键。例如,如果你在MySQL中使用MyISAM表,你就没有办法定义它。
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.