Module: DataMapper::NestedAttributes::OneToOne

Defined in:
lib/dm-accepts_nested_attributes/relationship.rb

Overview

Extensions for Associations::OneToOne::Relationship.

Instance Method Summary collapse

Instance Method Details

#extract_keys_for_nested_attributes(model, attributes) ⇒ Object



68
69
70
71
72
73
74
75
76
77
78
# File 'lib/dm-accepts_nested_attributes/relationship.rb', line 68

def extract_keys_for_nested_attributes(model, attributes)
  keys = self.child_model.key.to_enum(:each_with_index).map do |key, idx|
    if parent_idx = self.child_key.to_a.index(key)
      model[self.parent_key.to_a.at(parent_idx).name]
    else
      attributes[key.name]
    end
  end

  keys.any? { |key| DataMapper::Ext.blank?(key) } ? nil : keys
end