Module | Sequel::Plugins::NestedAttributes::ClassMethods |
In: |
lib/sequel/plugins/nested_attributes.rb
|
nested_attributes_module | [RW] | Module to store the nested_attributes setter methods, so they can call be overridden and call super to get the default behavior |
Allow nested attributes to be set for the given associations. Options:
If a block is provided, it is used to set the :reject_if option.
# File lib/sequel/plugins/nested_attributes.rb, line 107 107: def nested_attributes(*associations, &block) 108: include(self.nested_attributes_module ||= Module.new) unless nested_attributes_module 109: opts = associations.last.is_a?(Hash) ? associations.pop : {} 110: reflections = associations.map{|a| association_reflection(a) || raise(Error, "no association named #{a} for #{self}")} 111: reflections.each do |r| 112: r[:nested_attributes] = opts 113: r[:nested_attributes][:unmatched_pk] ||= opts.delete(:strict) == false ? :ignore : :raise 114: r[:nested_attributes][:reject_if] ||= block 115: def_nested_attribute_method(r) 116: end 117: end