views:

70

answers:

1

I have an application form and a library of questions, one application form may contain one or more questions. When user selects a question from the library and adds the question to the application form, he can add some new attributes to the question or override existing attributes of the question if he wants to. When the user finishes question selection, he can save the application form together with the questions selected.

My current table structures are like this:

TAB_FORM
--------
ID INT(10) NOT NULL,
...

TAB_QUESTION
------------
ID INT(10) NOT NULL,
...

TAB_FORM_QUESTION
-----------------
ID INT(10) NOT NULL,
FORMID INT(10) NOT NULL,
QUESTIONID INT(10) NOT NULL,
NEWATTRIBUTE1 VARCHAR(20),
NEWATTRIBUTE2 VARCHAR(20),
...

It works fine when user adds new attributes for some questions, but if user wants to override some existing attributes of a question, it doesn't work because the question is from a library which is read-only.

Could I just copy all the fields from TAB_QUESTION to TAB_FORM_QUESTION, or is there any other solution? Thanks.

A: 

I think I have to copy all the fields from TAB_QUESTION to TAB_FORM_QUESTION, then I can create a new class EmbeddableQuestion which is mapped to these fields and embed EmbeddableQuestion into class FormQuestion. EmbeddableQuestion may extends Question, but I don't think it is necessary.

Kevin Yang
Create a class EmbeddableQuestion seems cumbersome since Question itself has no more than 10 fields, so putting these fields in FormQuestion is OK. Life is easier now, ApplicationForm and FormQuestion are simply one-to-many relationship.
Kevin Yang