Module Sequel::Plugins::NestedAttributes::ClassMethods
In: lib/sequel/plugins/nested_attributes.rb

Methods

Attributes

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

Public Instance methods

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.
  • :remove - Allow disassociation of nested records (can remove the associated object from the parent object, but not destroy the associated object).
  • :strict - Set to false to not raise an error message if a primary key is provided in a record, but it doesn‘t match an existing associated object.

If a block is provided, it is passed each nested attribute hash. If the hash should be ignored, the block should return anything except false or nil.

[Source]

    # File lib/sequel/plugins/nested_attributes.rb, line 43
43:         def nested_attributes(*associations, &block)
44:           include(self.nested_attributes_module ||= Module.new) unless nested_attributes_module
45:           opts = associations.last.is_a?(Hash) ? associations.pop : {}
46:           reflections = associations.map{|a| association_reflection(a) || raise(Error, "no association named #{a} for #{self}")}
47:           reflections.each do |r|
48:             r[:nested_attributes] = opts
49:             r[:nested_attributes][:reject_if] ||= block
50:             def_nested_attribute_method(r)
51:           end
52:         end

[Validate]