module Neo4j::ActiveNode::Property::ClassMethods
Public Instance Methods
association_key?(key)
click to toggle source
# File lib/neo4j/active_node/property.rb 21 def association_key?(key) 22 association_method_keys.include?(key.to_sym) 23 end
extract_association_attributes!(attributes)
click to toggle source
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?
# File lib/neo4j/active_node/property.rb 14 def extract_association_attributes!(attributes) 15 return unless contains_association?(attributes) 16 attributes.each_with_object({}) do |(key, _), result| 17 result[key] = attributes.delete(key) if self.association_key?(key) 18 end 19 end
Private Instance Methods
association_method_keys()
click to toggle source
All keys which could be association setter methods (including _id/_ids)
# File lib/neo4j/active_node/property.rb 34 def association_method_keys 35 @association_method_keys ||= 36 associations_keys.map(&:to_sym) + 37 associations.values.map do |association| 38 if association.type == :has_one 39 "#{association.name}_id" 40 elsif association.type == :has_many 41 "#{association.name.to_s.singularize}_ids" 42 end.to_sym 43 end 44 end
contains_association?(attributes)
click to toggle source
# File lib/neo4j/active_node/property.rb 27 def contains_association?(attributes) 28 return false unless attributes 29 attributes.each_key { |k| return true if association_key?(k) } 30 false 31 end