如何组织信息(在MVC模型中)以表示这个真实的例子:
调查 - 可以有多个问题和多个会回答问题的人
问题 - 只有单一答案 - 是或否
PersonAnswer - 回答问题的人
示例显示:
到目前为止我的实施是:
DB
调查 - 问题 - 一对多
问题 - PersonAnswer - 一对多
控制器代码: - 伪代码
我的方法存在问题:
更新:我使用的是java和mysql。
答案 0 :(得分:1)
我对此问题的处理方法首先是处理数据库:
在我的情况下,我就是这样做的:
Have a table of
users->represents db users
surveyitems->with item(questions) and id(probaby autoincrement integer pkey),
surveycheks->representing the users and their checks having({
id(pkey),
checkid(foreign_key ->to surveyitems table id)
yeschecked(representing the yes)
nochecked(representi)ng the nos
})
然后在你的视图中,例如当使用yii php framework
时use gii tool to generate models and crud //here you can use your own
logic of saving data to db
On your survey form
1. load all surveys from table surveyitems with id and items()// display item
2. Have radio buttons with values of id(from survey items);
3.. when saving loop through all checked yes or nos and store them in surveycheks
我希望你明白这个想法