Hi Patrick,

When you are using "group_by" you are of course aggregating rows. So I am curious what database you are using that allows you to specify fields that in the select that are neither aggregate functions or part of the group.

Even if it returns values for those fields (books.*) what criteria does it use to set the value for those fields:
min
max
sum
etc.

I would probably create a view to if there were any possibility of porting to another db.

Best,
Carl


Patrick Crowley wrote:
Oooh, I got it.

Book.find(:all,
:page => {:size => 5, :current => params[:page]},
:joins => "LEFT JOIN book_copies ON book_copies. book_id = books.id",
:select => "books.*, count(*) as count",
:conditions => "books.id = book_copies. book_id AND books.access = 'released'",
:group => "book_copies. book_id",
:order => "count DESC",
:limit => 100)

For those who are curious, I needed to use #find instead of #find_by_sql because I'm using the paginating_find plugin (which overrides #find, and only #find, to make pagination easier).

-- Patrick

_______________________________________________
Sdruby mailing list
[email protected]
http://lists.sdruby.com/mailman/listinfo/sdruby


_______________________________________________
Sdruby mailing list
[email protected]
http://lists.sdruby.com/mailman/listinfo/sdruby

Reply via email to