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:
:destroy - Allow destruction of nested records.
:fields - If provided, should be an Array. Restricts the fields allowed to be modified through the association_attributes= method to the specific fields given.
:limit - For *_to_many associations, a limit on the number of records that will be processed, to prevent denial of service attacks.
:reject_if - A proc that is given each attribute hash before it is passed to its associated object. If the proc returns a truthy value, the attribute hash is ignored.
:remove - Allow disassociation of nested records (can remove the associated object from the parent object, but not destroy the associated object).
:strict - Kept for backward compatibility. Setting it to false is equivalent to setting :unmatched_pk to :ignore.
:transform - A proc to transform attribute hashes before they are passed to associated object. Takes two arguments, the parent object and the attribute hash. Uses the return value as the new attribute hash.
:unmatched_pk - Specify the action to be taken if a primary key is provided in a record, but it doesn’t match an existing associated object. Set to :create to create a new object with that primary key, :ignore to ignore the record, or :raise to raise an error. The default is :raise.
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
Add a nested attribute setter method to a module included in the class.
# File lib/sequel/plugins/nested_attributes.rb, line 123 123: def def_nested_attribute_method(reflection) 124: nested_attributes_module.class_eval do 125: if reflection.returns_array? 126: define_method("#{reflection[:name]}_attributes=") do |array| 127: nested_attributes_list_setter(reflection, array) 128: end 129: else 130: define_method("#{reflection[:name]}_attributes=") do |h| 131: nested_attributes_setter(reflection, h) 132: end 133: end 134: end 135: end
Disabled; run with --debug to generate this.
Generated with the Darkfish Rdoc Generator 1.1.6.