蛋糕烘焙模型生成(hasOne 与 hasMany)
我正在尝试使用“蛋糕烘焙”控制台命令来生成两个具有“belongsTo/hasOne”关系(来自数据库模式)的模型,并且它不断生成“belongsTo/hasMany”双向关系。
我正在遵循此指南,了解列名称约定的这些定义(“user_id”在配置文件,用户中的“profile_id”),但是,就像我说的,“蛋糕烘焙”总是出错。 “蛋糕烘焙”是否能够确定 hasOne 和 hasMany 之间的差异?有人有一个简单的 MySQL 模式示例吗?我正在使用 CakePHP 1.3.6
I'm trying to get the 'cake bake' console command to generate 2 Models with a belongsTo/hasOne relationship (from the database schema) and it keeps generating a belongsTo/hasMany two-way relationship.
I am following the this guide on these definitions for the column name conventions ('user_id' in Profile, 'profile_id' in User) but, like I said, 'cake bake' keeps getting it wrong. Is 'cake bake' capable of determining the difference between hasOne and hasMany? Does anyone have a simple MySQL schema example where this is working? I'm using CakePHP 1.3.6
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
从 SQL 模式的角度来看,hasOne 和 hasMany 关系是相同的,区别只是对相关记录的数量 (1) 进行了人为限制。
bake
无法区分。如果您使用交互过程,它应该首先建议更常见的 hasMany 关系,然后建议使用 hasOne 替代关系。hasOne and hasMany relationships are identical from an SQL schema perspective, the difference is simply that there's an artificial restriction on the number of related records (1).
bake
can't tell the difference. If you're using the interactive process, it should suggest the more common hasMany relationship first, and the hasOne alternative second.