Searching for a few recommendations regarding how to store my RoR data. Basically, I've 20 approximately products (won't ever exceed 50) that I have to track. The items includes a different X,Y coordinate each and every time (among either Morning, Mid-day, Evening), and each one of the seven mondays to fridays it features a different schedule (basically, 21 different x,y points for every time/day's week combination). Additionally, it has some static values, like the title, category, and whatnot.

At this time I am attempting to select how I wish to store it, individuals 21 different x,y points. I guess you will find two opposite extremes around the spectrum - either (a) store each area like wednesday_mid-day_x, wednesday_mid-day_y, etc, or (b) serialize and store like a hash/struct, like x.wednesday.mid-day or something like that. Another option could even be to interrupt them up into separate tables (ie possess a :tuesday_item, :wednesday_item models, etc)

One factor which i need to have the ability to do is search/filter by individuals fields - for instance, if I wish to obtain the products which are inside a specific Category for any given TimeOfDay and DayOfWeek.

What are the recommendations regarding the way i should proceed? Thanks!

I'd use two database tables, one for products, and something for coordinates. The schema then could be simple:

create_table :items do |t|
  t.string :name
  t.string :category
  t.string :whatnot
end

create_table :item_coordinates do |t|
  t.references :item
  t.integer :x
  t.integer :y
  t.string :time_of_day
  t.string :weekday
end

[UPDATE: Whenever you really create these migrations, don't didn't remember to include indexes! For item_coordinates, you most likely desire a joint index on [:item_id, :weekday, :time_of_day], try not to take my word for your -- discover which fields you really finish up using as secrets and index individuals.]

Your Item model would has_many :item_coordinates as well as your ItemCoordinate model would belong_to :item.

You'll be able to make use of all the standard ActiveRecord techniques. For instance, to obtain a specific coordinate easily under this technique:

item_coordinate = Item.find(item_id).item_coordinates.where(:time_of_day => 'afternoon', :weekday => 'wednesday')
coords = [item_coordinate.x, item_coordinate.y]