adam-cowley / neode

Neo4j OGM for Node.js
MIT License
394 stars 72 forks source link

Is there a way to eagerly load multiple nodes with a given relationship type? #156

Closed joostdecock closed 3 years ago

joostdecock commented 3 years ago

Hi there,

Thanks for making this library. I'm using it, but when I load a node (from primary key) with a bunch of eager relationships, it seems to only load 1 node per relationship.

Is there a way to tell it to load all related nodes for an eager relationship?

adam-cowley commented 3 years ago

Are you using the type nodes or relationships? For example:

{
  // ...
  friends: {
    type: 'nodes', // <-- plural
    target: 'Person',
    relationship: 'FRIENDS_WITH',
    direction: 'both'
  }  
}
joostdecock commented 3 years ago

I am now :smile:

tagged_with: {
     direction: 'out',
     eager: true,
     relationship: 'TAGGED_WITH',
     target: 'Tag',
     type: 'relationships',  //  <== Made this plural
}

Works like a charm :+1:

Thank you for your speedy response, much appreciated :pray:

jdarosaj commented 3 years ago

As a suggestion, fix the schema under https://github.com/adam-cowley/neode#eager-loading In there, the type is 'relationship' (which should be 'relationships') and below you use const first = movies.first(); as movies was an array, but it is not because of the type specified, so the example is inconsistent.