0

I have 3 nodes, B, C and D. I require similar associations between C and B, and D and B

To be DRY, rather than putting the 'has_many' individually on C and D, i created a super class A and added the association there, like so:

class A
  include Neo4j::ActiveNode
  has_many :out, :related_b_nodes, model_class: :B, type: :some_type
end


class B
  include Neo4j::ActiveNode
  has_many :in, :related_a_nodes, model_class: :A, origin: :related_b_nodes
end

When I inherit from A:

class C < A
end

class D < A
end

The code works alright when I test it through the rails console, but rspec continues to fail, displaying the message:

Association `related_b_nodes` defined for a second time.
  Associations can only be defined once (Class#related_b_nodes) (RuntimeError)

What might be the problem?

Shobhit Verma
  • 2,223
  • 2
  • 10
  • 17

1 Answers1

0

That definitely seems odd. Is the stacktrace for the error helpful at all?

You might also output the stack whenever it's trying to define the association so that you can trace down why this is happening. Something like:

class A
  include Neo4j::ActiveNode
  puts 'about to defined related_b_nodes at this point:', caller
  has_many :out, :related_b_nodes, model_class: :B, type: :some_type
end
Brian Underwood
  • 10,746
  • 1
  • 22
  • 34