On Dec 9, 11:52 am, Jay Mark <[EMAIL PROTECTED]> wrote: > Here is the table structure: > > Author has id, name, title, book_id and other columns > Book has id, title, isbn, and other columns. > > They both have the title column. And, yes, authors has book_id as a > foreign key > for books. > The inner query is to select title where name = the name that was passed > in as the query condition. Then the outer query will select all rows > where title is equal to the title returned by the inner query. > The strange thing here is, title has a unique entry in authors table, > but title has duplicate entries in the book table. > > So, the main point here is to get all rows from the book table that has > the same value as the title that was returned from the authors table, > which was selected based on the name that was passed in. > > I don't have a control over the table structure. So, changing it is not > an option.
Ok, so Author.find_by_name should definitely work: Author.find_by_name(params[:author][:name]) If that's not working, then maybe there's a problem with case sensitivity? For example, in Postgres, I have to use the ILIKE operator like this: Author.find :first, :conditions => ["name ILIKE ?", params[:author] [:name]] Once you have an author object, author.book should give you the book. Let me know if this helps...? Jeff purpleworkshops.com --~--~---------~--~----~------------~-------~--~----~ 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 rubyonrails-talk@googlegroups.com 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 -~----------~----~----~----~------~----~------~--~---