cakePhp添加记录问题
我有 3 张桌子:项目 {名称,id,category_id}
类别 {id,name,section_id}
sections {id,name}
如您所见,每个项目都与一个类别相关,每个类别又与一个部分相关。 我使用了烘焙选项并将其全部烘焙,好吧,不是全部.. 由于 Category.name 可以重复,并且由于它是显示字段,因此我发现自己处于一种无法知道我真正使用哪个类别的情况。
有什么想法吗?
I have 3 tables:item {name,id,category_id}
category {id,name,section_id}
sections {id,name}
As you can see, each item is related to a category, and each category is related to a section.
I used the bake option and got it all baked, well, not all..
since the Category.name can be duplicated, and since it is the displayed field, I find my self in a situation which prevent me of knowing which category I really use.
Any ideas?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
你可以做这样的事情。添加到您的类别模型:
您可以使用此虚拟字段根据其 id 和名称的组合来判断哪个类别是哪个类别。然而,虚拟字段也有一些限制。在这里阅读:http://book. cakephp.org/view/1608/Virtual-fields#!/view/1608/Virtual-fields
You could do something like this. Add to your Category model:
This virtual field you can use to tell which category is which based on the combination of its id and name. There are some limitations to virtual fields, however. Read about it here: http://book.cakephp.org/view/1608/Virtual-fields#!/view/1608/Virtual-fields
嗯,答案是:
使用
find('list')
,将recursive
选项设置为 ON,并使用 3 个字段(而不是 2 个)。这样它就可以将类别分组到各个部分下。
Well, the answer was:
Using
find('list')
, withrecursive
option ON, and with 3 fields instead of two.That way it grouped the categories under the sections.