假设我想用问题和几个选项作为答案来创建民意调查和测验。
我是否必须为此创建民意调查模型?
如何跟踪民意调查表中每个选项的百分比结果?
我应该使用民意调查答案选项制作另一张表吗?
民意调查问题和民意调查答案的表关系是什么?
这是正确的方法吗?
create table polls (id integer not null auto_increment primary key, question varchar(300) not null, mark tinyint not null, created datetime, modified datetime);
create table pollsanswers (id integer not null integer auto_increment primary key, poll_id integer not null, answer varchar(500) not null, mark tityint not null, created datetime, modified datetime);
create table quizes (id integer not null auto_increment primary key, question varchar(300) not null, mark tinyint not null, created datetime, modified datetime);
create table quizesanswers (id integer not null integer auto_increment primary key, quiz_id integer not null, answer varchar(500) not null, mark tityint not null, created datetime, modified datetime);
如果我做一个mysql表轮询,那么我可以访问并使用该表与帖子或其他控制器,还是我必须创建polls_controller.php和poll.php模型?
我可以在不制作新型号和控制器的情况下这样做吗?
答案 0 :(得分:1)
如果是我,我可能会有以下表格:
create table polls (
id integer not null auto_increment primary key,
created datetime,
modified datetime
);
create table quizzes (
id integer not null auto_increment primary key,
created datetime,
modified datetime
);
create table questions (
id integer not null auto_increment primary key,
model varchar(255) not null, -- Poll or Quiz, in this scenario
foreign_key integer not null,
question varchar(255) not null,
created datetime,
modified datetime
);
create table answers (
id integer not null auto_increment primary key,
question_id integer not null,
answer varchar(255) not null,
created datetime,
modified datetime
);
我的联想可能是这样的:
Poll hasMany Question
Quiz hasMany Question
Question belongsTo Poll, Quiz
Question hasOne Answer
Answer belongsTo Question
由于民意调查和测验都有组件问题,我会尝试巩固这个方面。为了解释这两种关系,我会Question
polymorphic。