On 1 June 2010 13:57, Tom Ha <[email protected]> wrote: > ...and that I'd like to avoid the find_by_sql method (raw SQL), if > possible.
Yes - do not use "find_by_sql" for this... But you *DO* need to know what the SQL is to generate the results you want. > I cannot figure out what parameter(s) (like :limit, :group, etc.) of the > find method I have to use to create the count "condition" in the find > statement. I have already posted you an example that groups, counts and queries according to your initial post. You could try looking at that SQL and then looking up the SQL components in the Rails documentation; or converting as much as possible, in as small steps as possible, and asking for help with what remains. It's *impossible* to just give you the Ruby code to do the find if you haven't given the exact model structure, or at least the exact SQL you want to generate. > Assume that we're in a simply Model_A :has_many Model_B case like... > > Book :has_many Authors > Again, I've shown you the SQL that does this, and the SQL that's in your log file I can guarantee looks not very similar to it. You will need to use the :group and :having parameters to duplicate those components of the SQL. You *can't* do "books.count" as in the DB there isn't a "count" column in the books table. -- You received this message because you are subscribed to the Google Groups "Ruby on Rails: Talk" group. To post to this group, send email to [email protected]. To unsubscribe from this group, send email to [email protected]. For more options, visit this group at http://groups.google.com/group/rubyonrails-talk?hl=en.

