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: <pre> @processed_products = State.find_by_name('processed').products @ordered_products = State.find_by_name('ordered').products - @processed_products </pre> 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
on 2007-01-06 11:39
on 2007-01-06 22:51
Im thinking the only way around this is to add a column closed_at then set this in a before_save model callback then create an association extension called current the adds the condition. closed_at = nil. Any thoughts?