Andre
Andre

Reputation: 385

Neo4j and Rails don't give me a model

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

Upvotes: 1

Views: 54

Answers (1)

Brian Underwood
Brian Underwood

Reputation: 10856

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?

Upvotes: 1

Related Questions