I am using Ruby on Rails v3.0.9 and I have the following code in a my model:
class User < ActiveRecord::Base
validates :users_role,
:inclusion => {
:in => UserRole.all.map(&:role)
},
:presence => true
end
When I browse an UserRole related page (that is, a page where an user object instance is involved - for example, the RoR conventional "show" or "index" views), and I inspect the log file I see that the UserRole SQL query is performed. That is, the UserRole.all.map(&:role)
run.
I would like to know how Ruby on Rails works for the above case. It concerns the performance? Is the UserRole.all.map(&:role)
lazy loaded?