假设我想创建一个带有问题和几个选项作为答案的民意测验。

我是否需要为此创建投票模型?

如何在民意调查表中跟踪每个选项的百分比结果?

我应该用民意测验答案选项制作另一张桌子吗?

民意测验问题和民意测验答案的表关系是什么?

这是正确的方法吗?

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,那么我可以访问该表并与post或其他控制器一起使用,还是必须创建polls_controller.php和poll.php模型?

我可以不做新的模型和控制器就能做到吗?

最佳答案

如果是我,我可能会有下表:

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

关于mysql - CakePHP模型问题,如何建立民意测验的表关系?,我们在Stack Overflow上找到一个类似的问题:https://stackoverflow.com/questions/7297854/

10-11 03:26