On 1 June 2010 13:45, Michael Pavling <[email protected]> wrote: > 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?
Michael To some extent I agree with Tom here, ideally it should be possible to get straight to the answer without going through the sql. The condition is that the number of authors for the book should be greater than 5 and that published should be true, so the requirement is fully defined, the question is how to tell active record that that is what is required. To some extent the framework has failed (or one is just trying to do something too complex for it) if one has to work out the sql first then work out how to tell ActiveRecord to generate that sql. Colin -- 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.

