开发者

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.*')
0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜