← Back to Upcase

How do I build these objects?

(João Daniel) #1

I have 6 types of “Status”. It can be Green, white, yellow, orange, red and purple. For each of those status I have some attributes: color_name (“Green”, “Yellow”, etc.), css_name (“green”, “yellow”, etc.) and hex_code ("#1aae88", “#fcc633”, etc.).

I have objects that will be associated with those status, so I can ask each object its status. I should also be able to get objects that have a specific status. It seems like the case for immutable objects. But it’s “so immutable” that I’m not sure if it should be on the database at all.

I’m not sure if it should be an ActiveRecord model, or a hard-coded model, maybe inheriting from a Status parent-class. If it’s an ActiveRecord model, I can associate it to an object by its id. If it’s a hard-coded object, I don’t know how it would be associated to an object.

However, if I use an ActiveRecord model, if the status are “created” in a different order, I don’t know anymore what is each Status. For example, there are sections of the site that just deals with red or purple objects. How can I hard code it to the code, if the Status may be created in a different order?

Do you guys see any pattern on it? Is there any best practice in creating this kind of objects?

0 Likes

(João Daniel) #2

One thing that occurred is that I can add those status on the same migration that I create the table, so the IDs are “immutable”. Is it ok to do that?

0 Likes

(Nailson Martins) #3

hi @jdanielnd, as far as i know, it’s ok. if status is an attribute of your object, go ahead and use the database to store it.

0 Likes