method
reader_method
reader_method(name, class_name, mapping, allow_nil)
private
Hide source
# File activerecord/lib/active_record/aggregations.rb, line 151 def reader_method(name, class_name, mapping, allow_nil) module_eval do define_method(name) do |*args| force_reload = args.first || false if (instance_variable_get("@#{name}").nil? || force_reload) && (!allow_nil || mapping.any? {|pair| !read_attribute(pair.first).nil? }) instance_variable_set("@#{name}", class_name.constantize.new(*mapping.collect {|pair| read_attribute(pair.first)})) end return instance_variable_get("@#{name}") end end end