Skip to content

Commit

Permalink
break out of extract_association_attributes! early
Browse files Browse the repository at this point in the history
  • Loading branch information
subvertallchris committed Apr 19, 2015
1 parent 765ec93 commit 65d970f
Show file tree
Hide file tree
Showing 2 changed files with 13 additions and 0 deletions.
5 changes: 5 additions & 0 deletions lib/neo4j/active_node/has_n.rb
Expand Up @@ -95,6 +95,10 @@ def associations
@associations ||= {}
end

def associations_keys
@associations_keys ||= []
end

# make sure the inherited classes inherit the <tt>_decl_rels</tt> hash
def inherited(klass)
klass.instance_variable_set(:@associations, associations.clone)
Expand Down Expand Up @@ -265,6 +269,7 @@ def default_association_query_proxy(name)
end

def build_association(macro, direction, name, options)
associations_keys << name
Neo4j::ActiveNode::HasN::Association.new(macro, direction, name, options).tap do |association|
@associations ||= {}
@associations[name] = association
Expand Down
8 changes: 8 additions & 0 deletions lib/neo4j/active_node/property.rb
Expand Up @@ -12,10 +12,18 @@ module ClassMethods
# 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)
end
end

private

def contains_association?(attributes)
attributes.each_key { |key| return true if associations_keys.include?(key) }
false
end
end
end
end

0 comments on commit 65d970f

Please sign in to comment.