[lnkForumImage]
TotalShareware - Download Free Software

Confronta i prezzi di migliaia di prodotti.
Asp Forum
 Home | Login | Register | Search 


 

Forums >

comp.lang.ruby

Question about using DISTINCT in ActiveRecord find method.

Mufaddal Khumri

1/12/2006 5:49:00 PM

Hi,

Am relatively new to the RoR world. My question is quite simple.

I have a query like such:

shipmentNumbers = Order.find_by_sql(["select distinct s.id from orders
o, line_items li, shipment_lines sl, shipments s where o.number=? and
o.id = li.order_id and li.id = sl.line_item_id and sl.shipment_id =
s.id", number])

The above query works fine. I wanted to do the same query using the
query below:

shipmentNumbers = Order.find(:all, :conditions => ["number =
?", number], :joins => "as o join line_items as li on o.id =
li.order_id join shipment_lines as sl on sl.line_item_id = li.id join
shipments as s on sl.shipment_id = s.id")

In the above query I need to add the "distinct s.id" equivalent for
getting the correct results. Does anybody have an idea as to how I would
use the DISTINCT clause in the find(..) method?

Thanks,

--
Posted via http://www.ruby-....


1 Answer

Austin Ziegler

1/12/2006 6:43:00 PM

0

On 12/01/06, Mufaddal Khumri <mkhumri@allegromedical.com> wrote:
> Am relatively new to the RoR world. My question is quite simple.

You'll probably get a faster answer on this from:

http://lists.rubyonrails.org/mailman/list...

-austin
--
Austin Ziegler * halostatue@gmail.com
* Alternate: austin@halostatue.ca