Louis Sayers
Louis Sayers

Reputation: 2219

Neo4j gem undefined method `name' for CypherNode

I'm currently experiencing an issue where it looks like CypherNodes aren't being converted into their corresponding model objects properly.

Interestingly enough, if I clear my DB locally, the error stops occurring, but will sure enough occur sometime later. Once it has occurred it consistently produces the error.

The main bit of code where the issue occurs resembles the following:

results = Club.query_as(:club)
             .match("(region:Region)-[:has_club]->(club)")
             .match("(club)-[:last_event]->()<-[:next*0..]-(event)-[:action]->(game)")
             .match("(game)<-[:action]-(:Event)<-[:next*0..]-()<-[:first_event]-(member:Member)")
             .where(region: { name: region_name }, club: { name: club_name })
             .order(event: { created_at: :desc })
             .limit(limit)
             .pluck(:member, :event, :game)


  results.map do |member, event, game|
    # Error occurs on 'game.name' as game is a CypherNode, not a Game object
    view_model = GameViewModel.new(game: game.name,
                                   member_name: member.nickname,
                                   created_at: event.created_at.to_i)
  end

When the problem occurs, this results in an array with items that look like:

[ 
  CypherNode 1139 (70254694683340), 
  #<Event uuid: "c3b81116-1be3-4722-8908-8c36d5c76fe3", created_at: Wed, 19 Aug 2015 03:53:43 +0000>, 
  CypherNode 993 (70254694681800)
 ]

If I look into each CypherNode (node.labels, node.props), I can see that it has the correct label in an array, and the correct properties on it.

The member model is quite complex, but the game model is very simple and looks like:

class Game
  include Neo4j::ActiveNode
  property :name, type: String
end

I'm kind of stuck with this, not knowing exactly what to look at. Any thoughts or suggestions would be much appreciated!

Upvotes: 1

Views: 113

Answers (2)

subvertallchris
subvertallchris

Reputation: 5482

This is related to a bug that was patched in 5.1.5, regressed in 5.2.0-5.2.2, fixed again in release 5.2.3. https://github.com/neo4jrb/neo4j/issues/955 addresses it.

Upvotes: 2

Brian Underwood
Brian Underwood

Reputation: 10856

That is certainly strange! Some thoughts:

  • I think you already covered this, but the labels should be Member and Game (case-sensitive). I see your matching on Member in the query but not on Game (that doesn't matter as long as the label on the node is right, but just to check)
  • If you're using self.mapped_label_name in your model that could affect things
  • Do any of these nodes have multiple labels? Again, I don't think that will make a difference, but it's good to know

Upvotes: 0

Related Questions