ruby-on-rails3, and select distinct using activereccord3
Some methods开发者_StackOverflow中文版 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
Just use the new select
query method.
Error.select('DISTINCT type')
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.*')
精彩评论