| 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 passed each nested attribute hash. If the hash should be ignored, the block should return anything except false or nil.
# File lib/sequel/plugins/nested_attributes.rb, line 42
42: def nested_attributes(*associations, &block)
43: include(self.nested_attributes_module ||= Module.new) unless nested_attributes_module
44: opts = associations.last.is_a?(Hash) ? associations.pop : {}
45: reflections = associations.map{|a| association_reflection(a) || raise(Error, "no association named #{a} for #{self}")}
46: reflections.each do |r|
47: r[:nested_attributes] = opts
48: r[:nested_attributes][:reject_if] ||= block
49: def_nested_attribute_method(r)
50: end
51: end