Larry Kluger wrote:
If I eagerly load a collection during the initial find, do scoped
find_by_ calls later _always_ use sql?
Yes.
What is the best pattern to use to not do another db trip?
Is there some specialized rails method to handle this case?eg
Author
has_many :bookslarry = Author.find_by_name('larry', :include => :books)
ruby = larry.books.find_by_title('Ruby') # does this ALWAYS do a db
call?# Is the following the best way to get the one (or nil) book?
temp = larry.books.select{|book| book.title == 'ruby'}
ruby = temp.size == 1 ? temp[0] : nil
Yes. Or ruby = larry.books.detect {|book| book.title == 'ruby'}