使用 PHPcake 烘焙正确的数据库命名
刚刚开始 MVC 开发和蛋糕实现,所以我对表命名和 id 引用感到困惑。
我有一个名为资产的表,资产中存储的值是 asset_status_id 字段,它是对表 Asset_Statuses 的引用,该表是资产在任何时候可能处于的可能状态的简单列表(活动、非活动、已售出、维护等)我选择为此列表使用一个表:a)我想我有时需要添加更多选项b)我在这个表中有一个“序列”字段,这样我可以控制它们的排序顺序出现在任何下拉菜单中。
“Cake Bake”似乎将一个名为 Asset_Statuses 的表视为其存在的指示,用于描述 Assets 表和不存在的 Statuses 表之间的关系。现在我知道你的想法就是把桌子称为雕像吧?但我想使用其他“状态”表,例如 Domain_Status 当然不会使用相同的状态列表。
那么我应该使用什么命名约定来使这一切变得容易呢?
Just gettign into MVC developement and cakes implimentation, so I'm getting confused with table naming and id references.
I hava a table called Assets and value sotered in Assets is asset_status_id field which is meant to be a reference to the table Asset_Statuses this table is a simple list of possible statuses the assets could be in at any one time (Active, Inactive, Sold, Maintenace etc) I have chosen to use a table for this list as a) I think I'll need to add more options at some time b) I have a 'sequence' field in this table so I can control the sort order they will apear in in any drop downs.
'Cake Bake'ing seems to see a table called Asset_Statuses as an indication it exists to descibe a relations ship between the Assets table and a non-existent Statuses table. Now I know what your thinking just call the table Statues right? But I have oither 'Status' tables I'd like to use such as a Domain_Status which wont use the same status lists of course.
So what s the naming convention I should be using to make this all work easily?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
使用状态表可能会更好,因为它可以用于所有地方,而不仅仅是资产。这可以轻松地添加模型字段(例如其 id、模型、状态)来完成。
那么你的加入只有一个条件。
您可以使用一种行为来自动设置 beforeSave 中的模型字段
作为旁注,所有表都应全部小写,而不是您正在使用的有趣的大小写。这可能是事情没有按应有的方式进行的原因。
you might just be better off using a statuses table, as it can be used all over and not just for the assets. this can be done easily adding a model field, so its id, model, status.
then your join just has a condition.
you can use a behavior to automate the setting of the model field in beforeSave
As a side note, all tables should be all lower case, not the funny case you are using. This may be the cause of things not working the way they should.
我不确定资产状态的复数形式是资产状态(您应该检查),并且表格也需要小写,因此 asset_states,而不是 Asset_States。但您可以在模型中使用完全不同的表。检查这个。所以基本上创建一个模型,根据你的喜好命名。即 AssetState 和 put:
我认为你不会有问题。只需确保在您的关系 isn'tateTo, hasMany 中您提供了正确的类名,即:
I am not sure that the plural of Asset Status is Asset States (you should check) and also the table need to be lower case, so asset_states, not Asset_States. But you can use a totally different table in your models. Check this. So basically create a model, name it as you like. I.e. AssetState and put:
and I think you won't have problems. Just be sure that in your relation belongsTo, hasMany you provide the proper class name i.e.: