1

I'm using neo4j with neo4jrb. In irb I use this query:

p = Tag.as(:t).where("t.value = 'Andre'").names(:n).pluck(:n)

I expect to get with p.first a model from type Person. But as result I get only a CypherNode 3 (53012760). The 3 is the ID from the personmodel. But I can't get the model, what am I doing wrong?

Here my models and relationships:

class Tag
    include Neo4j::ActiveNode
    property :value, index: :exact, constraint: :unique
    ... more outs ....
    has_many :out, :names, rel_class: Names
end

class Names
   include Neo4j::ActiveRel

   from_class Tag
   to_class Person

   type 'name'
end

class Person 
    include Neo4j::ActiveNode

    has_many :in, :named, rel_class: Names
end
Andre
  • 385
  • 1
  • 13

1 Answers1

1

When I try it locally (neo4j gem version 6.0.1) it works, though some changes so that it wouldn't fail when I pasted it into irb. Specifically I passed in symbols rather than classes to rel_class, from_class, and to_class so that there aren't load order issues:

class Tag
    include Neo4j::ActiveNode
    property :value, index: :exact, constraint: :unique

    has_many :out, :names, rel_class: :Names
end

class Names
   include Neo4j::ActiveRel

   from_class :Tag
   to_class :Person

   type 'name'
end

class Person 
    include Neo4j::ActiveNode

    has_many :in, :named, rel_class: :Names
end

If that doesn't help, you might try removing other code from your models to see if there is anything else that's causing the problem.

Also, are your models all under app/models and named correctly?

Brian Underwood
  • 10,746
  • 1
  • 22
  • 34
  • This works. Very nice. Could you explain what is the difference or why my version didn't work as expected? – Andre Dec 14 '15 at 11:44
  • 1
    I'm not 100% sure, but if, for example, your `Tag` model tries to load first it will try to access the `Names` constant. If that's not yet defined, there might be an error that you didn't notice. If you're using Rails then the AutoLoad functionality from ActiveSupport should take care of that, but you can still have issues with circular references. I haven't investigated those very closely – Brian Underwood Dec 14 '15 at 14:11