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 110 110: def nested_attributes(*associations, &block) 111: include(self.nested_attributes_module ||= Module.new) unless nested_attributes_module 112: opts = associations.last.is_a?(Hash) ? associations.pop : {} 113: reflections = associations.map{|a| association_reflection(a) || raise(Error, "no association named #{a} for #{self}")} 114: reflections.each do |r| 115: r[:nested_attributes] = opts 116: r[:nested_attributes][:unmatched_pk] ||= opts.delete(:strict) == false ? :ignore : :raise 117: r[:nested_attributes][:reject_if] ||= block 118: def_nested_attribute_method(r) 119: end 120: end