Skip to content

Latest commit

 

History

History
79 lines (29 loc) · 1.1 KB

ClassMethods.rst

File metadata and controls

79 lines (29 loc) · 1.1 KB

ClassMethods

Constants

Files

Methods

#association_key?

def association_key?(key)
  association_method_keys.include?(key.to_sym)
end
#extract_association_attributes!

Extracts keys from attributes hash which are associations of the model TODO: Validate separately that relationships are getting the right values? Perhaps also store the values and persist relationships on save?

def extract_association_attributes!(attributes)
  return unless contains_association?(attributes)
  attributes.each_with_object({}) do |(key, _), result|
    result[key] = attributes.delete(key) if self.association_key?(key)
  end
end