一桌二款
我有帖子表
编号
类型枚举(A,Q)
标题
内容
,我需要控制器 questions_controller 和 answer_controller 来使用
请引导正确的道路到
1-
制作 2 个模型(问题和答案)并使用“帖子”作为模型的表
2-
在questions_controller和answer_controller中使用post模型
i have posts table
id
type enum(A,Q)
title
content
and i need controllers questions_controller and answer_controller to use
please lead the right way to
1-
make 2 models (question and answer) and use 'posts' as model's table
2-
use post model in questions_controller and answer_controller
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
对我来说,应该是一张桌子有一个型号
所以更好用
$uses = array('Post');在你的控制器中。
更新:
据我了解,您想要根据类型列过滤数据。实际上你的数据库模型是错误的,因为除非它们完全不相关,否则你的答案需要属于问题。这意味着您需要一个额外的列parent_id,它将确定什么是父节点(问题)和子节点(答案)。
如果我们有这个假设,那么您可以在模型中设置一个关系,例如:
因此您自动具有 Post 和 Post->Parent。但我认为最好有两张桌子——一张放问题,另一张放答案。
For me, it should be one table has one model
So better use
$uses = array('Post'); in your controllers.
Update:
As far I understood you want to filter the data depending from the type column. Actually your db model is wrong, because except if they are totally unrelated your answers need to belong to the question. This mean you need an extra column parent_id which will determine what is the parent node (question) and child nodes (answers).
If we have this assumption, then you can set a relation in the model like:
So you automatically have Post and Post->Parent. But I think that it would be better to have 2 tables - one which holds the questions and another the answers.