Module: Sequel::Plugins::NestedAttributes::InstanceMethods
- Defined in:
- lib/sequel/plugins/nested_attributes.rb
Instance Method Summary collapse
-
#set_nested_attributes(assoc, obj, opts = OPTS) ⇒ Object
Set the nested attributes for the given association.
Instance Method Details
#set_nested_attributes(assoc, obj, opts = OPTS) ⇒ Object
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.
163 164 165 166 167 168 169 170 171 172 173 174 |
# File 'lib/sequel/plugins/nested_attributes.rb', line 163 def set_nested_attributes(assoc, obj, opts=OPTS) raise(Error, "no association named #{assoc} for #{model.inspect}") unless ref = model.association_reflection(assoc) raise(Error, "nested attributes are not enabled for association #{assoc} for #{model.inspect}") unless = ref[:nested_attributes] return if obj.nil? && [:reject_nil] = .merge(opts) [:reflection] = ref if ref.returns_array? nested_attributes_list_setter(, obj) else nested_attributes_setter(, obj) end end |