I have a really quick question on the number of SQL calls I am seeing in
my development log when it comes to associations. This may just be an
environment issue, but I could not find an answer.
If I have a belongs_to association for books to a library for example.
class Library < ActiveRecord::Base
has_many :books
end
Sorry about the previous message I accidentally sent it before
completing it.
I have a really quick question on the number of SQL calls I am seeing in
my development log when it comes to associations. This may just be an
environment issue, but I could not find an answer.
If I have a belongs_to association for books to a library for example.
class Library < ActiveRecord::Base
has_many :books
end
class Book < ActiveRecord::Base
belongs_to :library
end
If I am iterating over a collection of books in a view like so,
<% for b in @books %>
<%=h b.name %>,
<%= b.library.name %>
<%= b.library.city %>, <%= b.library.state %>
<% end %>
For each time through the loop there are 3 SQL call for the Library
information. One for each of the outputs where the Library is
referenced. Is this how this is supposed to work? Again, this is all
in a development environment, does the production behave differently?
Or, is there some kind of caching mechanism I am not taking advantage
of?
Sorry about the previous message I accidentally sent it before
completing it.
I have a really quick question on the number of SQL calls I am seeing in
my development log when it comes to associations. This may just be an
environment issue, but I could not find an answer.