I have a Question which can have many statuses (Open, Closed,
Expired, etc) I have made a Question_Statuses Table to link to my
Question Table. The model by default created by Rails makes the ID
auto increment. I dun want the auto increment so i can change and
delete statuses and have control of them as they link to my questions.
I dunno if there is a better way to do this but i was thinking to have
unique ID’s (no-increment) eg. 1-5 and give them names, and my
questions have a status_id which points to a status.
how would i go about implementing this in rails? and is there a
better way to do it im missing ?
I have a Question which can have many statuses (Open, Closed,
Expired, etc) I have made a Question_Statuses Table to link to my
Question Table. The model by default created by Rails makes the ID
auto increment. I dun want the auto increment so i can change and
delete statuses and have control of them as they link to my questions.
I dunno if there is a better way to do this but i was thinking to have
unique ID’s (no-increment) eg. 1-5 and give them names, and my
questions have a status_id which points to a status.
What is the purpose of having a status table if they are simply
constants?
If you’re depending on the id being a particular value, then why not
just omit the table and assign the status directly to the Question?
On the other hand, if you plan on looking up the description of the
status, then you can’t go around changing them and deleting them
later. If you do, then your Questions will be pointing to either non-
existent or incorrect states.
If your needs are simple, just have a status String in the question
and put the name of the state right in there. As in
question.status = “open”
If you are doing something complex, there’s an acts_as_state_machine
plug-in.