Tech Per: ActiveRecord and HAVING clauses

Found this good discussion on the subject, where Blake Watters suggests adding support for ””:having”” on find to the core of ActiveRecord. I agree on this being a needed feature, but there is also a mention of a work-around, that I am using now. Simply put your HAVING clause last in the ””:group”” key.

ActiveRecord#findに:havingとか無いなあとおもったら:groupに書けるらしい。

Tags.find(:all, :select => 'COUNT(id) AS count, name', :group => 'name <strong>HAVING count > 1</strong>')

書けた。ほう。

Comments


Option