CREATE TABLE question
(
id
int(10) unsigned NOT NULL AUTO_INCREMENT,
title
varchar(150) NOT NULL DEFAULT '',
body
text NOT NULL,
PRIMARY KEY (id
),
) ENGINE=InnoDB DEFAULT CHARSET=utf8;
CREATE TABLE answer
(
id
int(10) NOT NULL,
body
text NOT NULL,
questionId
int(10) NOT NULL DEFAULT '0',
PRIMARY KEY (id
),
) ENGINE=InnoDB DEFAULT CHARSET=utf8;
CREATE TABLE comment
(
id
int(10) NOT NULL,
body
varchar(255) NOT NULL,
itemType
tinyint(3) unsigned NOT NULL DEFAULT '0', // 1 => 'question', 2=> 'answer'
itemId
int(10) unsigned NOT NULL DEFAULT '0', // questionId or answerId
PRIMARY KEY (id
)
) ENGINE=InnoDB DEFAULT CHARSET=utf8;
as related comments determined by itemType and itemId, how to define the relationship between question-comment or answer-comment?