# Table for status

**URL:** <https://www.ruby-forum.com/t/table-for-status/120538>\
**Category:** Rails\
**Created:** [November 18, 2007, 4:04am UTC](https://www.ruby-forum.com/t/table-for-status/120538 "2007-11-18T04:04:52Z")\
**Posts on this page:** 4\
**Page:** 1

<div class="post-metadata">

**Author:** ![Chubbs](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/c/47e85d/32.png) [@Chubbs](https://www.ruby-forum.com/u/Chubbs)\
**Post date:** [November 18, 2007, 4:04am UTC](https://www.ruby-forum.com/t/table-for-status/120538/1 "2007-11-18T04:04:52Z")

</div>

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 ?

---

<div class="post-metadata">

**Author:** ![Chubbs](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/c/47e85d/32.png) [@Chubbs](https://www.ruby-forum.com/u/Chubbs)\
**Post date:** [November 18, 2007, 4:39am UTC](https://www.ruby-forum.com/t/table-for-status/120538/2 "2007-11-18T04:39:56Z")

</div>

On Nov 17, 2007, at 9:04 PM, Chubbs wrote:

> 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.

---

<div class="post-metadata">

**Author:** ![Chubbs](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/c/47e85d/32.png) [@Chubbs](https://www.ruby-forum.com/u/Chubbs)\
**Post date:** [November 19, 2007, 6:05am UTC](https://www.ruby-forum.com/t/table-for-status/120538/3 "2007-11-19T06:05:29Z")

</div>

On Nov 17, 2007 9:39 PM, George B. [removed\_email\_address@domain.invalid](mailto:removed_email_address@domain.invalid) wrote:

> What is the purpose of having a status table if they are simply  
> constants?

Normalization. Some DB types feel the DB should hold valid column  
values, since it may be accessed in multiple ways.

–Michael

---

<div class="post-metadata">

**Author:** ![Chubbs](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/c/47e85d/32.png) [@Chubbs](https://www.ruby-forum.com/u/Chubbs)\
**Post date:** [November 18, 2007, 5:03am UTC](https://www.ruby-forum.com/t/table-for-status/120538/4 "2007-11-18T05:03:53Z")

</div>

only reason why was having in separate table is so if i wanted to  
change the name or add descriptions to the status, or even change the  
order etc.

If i was going to store the statuses in the Question table, how would  
i define in Rails the global variables for my statuses ?
