module Sequel::Plugins::NestedAttributes::InstanceMethods

  1. lib/sequel/plugins/nested_attributes.rb

Methods

Public Instance

  1. set_nested_attributes

Public Instance methods

set_nested_attributes(assoc, obj, opts=OPTS)

Set the nested attributes for the given association. obj should be an enumerable of multiple objects for plural associations. The opts hash can be used to override any of the default options set by the class-level nested_attributes call.

[show source]
    # File lib/sequel/plugins/nested_attributes.rb
163 def set_nested_attributes(assoc, obj, opts=OPTS)
164   raise(Error, "no association named #{assoc} for #{model.inspect}") unless ref = model.association_reflection(assoc)
165   raise(Error, "nested attributes are not enabled for association #{assoc} for #{model.inspect}") unless meta = ref[:nested_attributes]
166   return if obj.nil? && meta[:reject_nil]
167   meta = meta.merge(opts)
168   meta[:reflection] = ref
169   if ref.returns_array?
170     nested_attributes_list_setter(meta, obj)
171   else
172     nested_attributes_setter(meta, obj)
173   end
174 end