Skip to content

Commit

Permalink
fix origin
Browse files Browse the repository at this point in the history
  • Loading branch information
subvertallchris committed Aug 14, 2014
1 parent 453d3e9 commit 1dfbc5e
Show file tree
Hide file tree
Showing 2 changed files with 25 additions and 9 deletions.
22 changes: 13 additions & 9 deletions lib/neo4j/active_node/has_n/association.rb
Expand Up @@ -62,6 +62,16 @@ def perform_callback(caller, other_node, type)
caller.send(callback(type), other_node)
end

def relationship_type(create = false)
if @relationship_type
@relationship_type
elsif @origin
origin_type
else
(create || exceptional_target_class?) && "##{@name}"
end
end

private

def get_direction(relationship_cypher, create)
Expand All @@ -86,15 +96,9 @@ def get_properties_string(properties)
end.join(', ')
p.size == 0 ? '' : " {#{p}}"
end

def relationship_type(create = false)
if @relationship_type
@relationship_type
elsif @origin
"##{@origin}"
else
(create || exceptional_target_class?) && "##{@name}"
end

def origin_type
target_class.associations[@origin].relationship_type
end

# Return basic details about association as declared in the model
Expand Down
12 changes: 12 additions & 0 deletions spec/unit/association_spec.rb
Expand Up @@ -132,6 +132,18 @@ class Default

end

describe 'origin_type' do
let(:start) { Neo4j::ActiveNode::HasN::Association.new(:has_many, :in, 'name') }
let(:myclass) { double("another activenode class") }
let(:myassoc) { double("an association object" )}
let(:assoc_details) { double("the result of calling :associations", relationship_type: 'MyRel')}
it 'examines the specified association to determine type' do
expect(start).to receive(:target_class).and_return(myclass)
expect(myclass).to receive(:associations).and_return(myassoc)
expect(myassoc).to receive(:[]).and_return(assoc_details)
expect(start.send(:origin_type)).to eq 'MyRel'
end
end
end


Expand Down

1 comment on commit 1dfbc5e

@subvertallchris
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Found that origin was only working correctly when it was pointed at an automatically named type. This looks at the other side association and sets the type to match in all cases.

Please sign in to comment.