Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

ruby-on-rails3, and select distinct using activereccord3

Some methods have been deprecated with Rails3. It is the case in particular with the following call !

Error.find(:all, :select => 'DISTINCT type')

Is anybody have an idea, how to convert this call to an ActiveRecord3 valid statement ?

I found nothing on the web ...

Thanks

like image 650
Arkan Avatar asked May 26 '10 15:05

Arkan


2 Answers

Just use the new select query method.

Error.select('DISTINCT type')
like image 78
Samuel Avatar answered Oct 31 '22 06:10

Samuel


If you seek to get a distinct set of returns against a PostGreSQL database, you must use:

Error.select('DISTINCT ON(type)')

and if your in the context of a scope, perhaps something like the following to ensure that you get all the fields:

scope :running, select('DISTINCT ON(campaigns.budget) campaigns.*')
like image 1
New Alexandria Avatar answered Oct 31 '22 08:10

New Alexandria