I have 3 tables, that provide a restful mechanism for creating history
for products. There is a list of (almost static) states that are linked
to a product via a progressions table.
eg states
1 ordered
2 processed
3 sent
PROBLEM
Im interested in getting the release list for a given state, eg
State.find_by_name(‘ordered’).products
When i progress a product to processed, that product will still appear
in the ordered list. At the moment i am doing the following, its rather
clumsy:
@processed_products = State.find_by_name('processed').products @ordered_products = State.find_by_name('ordered').products - @processed_products
This works fine, but now i need to get a count for the tabs (like in
google), and running all those selects seems over kill and SLOW. Ive
been looking at creating a query on the progression object using a
combination of order and distinct, or perhaps an association extension.
But just cant work it out…
TABLES
states
id
name
products
id
name
etc
progressions
id
state_id
product_id
created_by
created_at