Yii Gii 如何检测 MANY_MANY
我的数据库结构有几个 MANY_MANY 链接。然而,Gii(在我的例子中是 giix)并不总是将它们生成为 MANY_MANY,而是使用联合表生成 HAS_MANY。
是否有规则来确保 Gii 建立正确的关系?它查看列的名称吗?表的名称?索引?外键名称?如果联表中还有其他列怎么办?
My database structure has several MANY_MANY links. However Gii (giix in my case) does not always generate them as MANY_MANY, instead it generates a HAS_MANY with the joint table.
Are there rules to make sure Gii does the correct relationship? Does it look at the name of the columns? Names of the tables? Indexes? Foreign key names? What if there are other columns in the joint table?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
Gii 实际上检查每个表以查看是否存在连接表(请参阅 gii/generators/model 中的
ModelCode::isRelationTable()
)。如果满足以下条件,它将表检测为联接表:Gii 然后在参与模型之间创建多对多关系。
Gii actually checks every table to see if there are join tables (see
ModelCode::isRelationTable()
in gii/generators/model). It detects a table as a join table if:Gii then creates a many-to-many relationship between the participating models.
Gii 在模型中创建许多一对多 (1:n) 关系 self::BELONGS_TO + self::HAS_MANY
self::MANY_MANY 需要手动输入
Gii creates many One to Many (1:n) relations self::BELONGS_TO + self::HAS_MANY in models
self::MANY_MANY need type manually