Option 'rel_length ' in Neo4j.rb doesn't work properly

76 Views Asked by At

It's issue similar to this question , but in my case 'neo4j-core' gem version is updated from 7.0.4 to 8.1.0, and 'neo4j' 8.0.7 -> 8.3.4

class Person
  include Neo4j::ActiveNode
  has_one :out, :ancestor, rel_class: :HasFather
end

class HasFather
  include Neo4j::ActiveRel
  from_class :Person
  to_class :Person
  type 'HAS_FATHER'
end

There is 'show' method where I have code

@ancestors = @person.ancestor(rel_length: 1..4)

Before update it worked perfectly and method returned an array with 4 persons. But now it return only one person.

Person#ancestor 
  MATCH (previous:`Person`)
  WHERE (ID(previous) = {ID_previous})
  OPTIONAL MATCH (previous)-[rel1:`HAS_FATHER`]->(next:`Person`)
  RETURN 
    ID(previous), 
    collect(next) | {:ID_previous=>38}
ETHON: performed EASY effective_url=http://localhost:7474/db/data/transaction/commit response_code=200 return_code=ok total_time=0.01983900000000005

@ancestors = #<AssociationProxy Person#ancestor [#<Person uuid: "f4454bcb-ffc8-4050-a486-0e7172ea864a", generation: nil, name...
2

There are 2 best solutions below

1
InverseFalcon On

That cypher query isn't showing a variable-length relationship. Assuming previous only has a single father, you're always collecting on a single node at most.

You may want to review the syntax for variable-length patterns:

OPTIONAL MATCH (previous)-[rel1:`HAS_FATHER`*..4]->(next:`Person`)
1
Brian Underwood On

I'm looking into this, but I'm curious what happens when you do this:

@ancestors = @person.ancestor(nil, nil, rel_length: 1..4)

I'm looking at the difference between 8.1.5 and 8.2.1 and it seems to be mostly around with_associations. I'm pretty sure rel_length is still working in general after 8.2.x, but if that line of code doesn't work then maybe I'm wrong about that....