On 1 June 2010 13:03, Tom Ha <[email protected]> wrote:
> Thanks - and no worries re the model, it's just an example...

If the code you post is an example, then SQL I posted won't work. As I
said, I'd suggest you get the SQL working for your specific situation,
and then try to get the Rails find to generate the right SQL - you can
compare the output in the log file to the SQL you know works.
The SQL I posted does *exactly* what you asked for (at least here on
models of mine it does)... have you run it to see what it does for
you?

> Actually, I asked this question since I'd like to stick as much as
> possible to the "Rails way" of doing things (and therefor I'd like to
> try to avoid things like "original" SQL statements).

Of course, but until you know what resulting SQL statement you want to
get to, how can you form the finder options?

> So, any idea how the part...
>
>   :conditions => "books.published = TRUE AND
>                   number-of-authors-must-be-greater-than-5"
>
> ...would have to be? (In the Rails kind of way?)
>
> (I tried using the API, but don't seem to get it.)

What part of the documentation don't you "get"?
http://api.rubyonrails.org/classes/ActiveRecord/Base.html

If there's part of it that doesn't make sense, then we can try to help out.

Get the SQL working for your specific requirement (so you're not
guessing with "example" models), and then figure how to get AR to
generate it. The documentation explains about JOINS, GROUP BY and
HAVING - all the components of the SQL you need to get your job done.

Worst case scenario; post the working SQL here and ask "how can I
generate this exact SQL in an AR find method?".

-- 
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.

Reply via email to