:group usage


I have the following code that is close to working the way I want it
Dispatch.find(:all, :group => :order_id, :conditions =>
[“ex_factory_date < ?”, (Date.today + 1.month)], :order
=> :ex_factory_date)

So let me quickly explain what is going on. I have orders that have
many dispatches. I am trying to make a report so that I find the
earliest dispatch of an order and then not to show any more dispatches
for that order. So my data is basically like this:
Order 1 has 3 Dispatches with the following ex_factory_dates:
Dispatch 1 = 12/10/2010
Dispatch 2 = 13/10/2010
Dispatch 3 = 20/10/2010

Order 2 has 2 Dispatches with the following ex_factory_dates:
Dispatch 1 = 15/10/2010
Dispatch 2 = 11/10/2010

So in my code I am using :group to ensure the order_id is unique which
it does. The only problem is that it seems to only select the last
dispatch and I can not think of a way to make it select the dispatch
with the earliest ex_factory_date. Hope that makes sense and any help
much appreciated. I may be going about this the wrong way not sure.

This forum is not affiliated to the Ruby language, Ruby on Rails framework, nor any Ruby applications discussed here.

| Privacy Policy | Terms of Service | Remote Ruby Jobs