brikteknologier / seraph-model

thin model layer for seraph/neo4j (node.js)
MIT License
111 stars 28 forks source link

Show relationships in all associated nodes? #119

Closed andyrichardson closed 7 years ago

andyrichardson commented 8 years ago

Is there a way to compose a relationship so that it exists in both the root and associated node, without redundancy (virtually bidirectional)?

Issue

Andy's node

{
    name: andy,
    friends: [
        { name: joe }
    ]
}

Joe's node

{
    name: joe
}

Desired result

Andy's node

{
    name: andy,
    friends: [
        { name: joe }
    ]
}

Joe's node

{
    name: joe
    friends: [
        { name: andy }
    ]
}

Ideally I'd like to find a way to do this at the composition stage although if it is possible to achieve the desired results at the fetching stage, that would also be okay.

How do I achieve this using a where or similar model function?

andyrichardson commented 8 years ago

I've been looking at commit #85 and it seems as though composed relationships can only be composed as either 'ingoing' or 'outgoing' - understandable seeing as neo4j requires direction to be specified.

I've been looking through the options for model.where and it seems unclear as to retrieving relationships which aren't composed.

rel the relationship relating the root node and this model

Does this mean the relationship label? Obviously if I'm looking to retrieve the relationship/s then I will not be able to provide it.

direction (optional - default: out) the direction of the relationship

What are the other options, I'm assuming in and any?


I've tried the following with no luck (no errors or 'has_friend' relationships being returned).

...
include: [{
            model: model,
            rel: 'has_friend',
            direction: 'any',
            many: true
        }]
...
jonpacker commented 7 years ago

Hey! As you say, neo4j does not support directionless relationships, so it doesn't make a whole lot of sense to support that on compositions. Your fix is the best way of supporting this. Thanks for the work!

andyrichardson commented 7 years ago

@jonpacker Thanks for the response. While neo4j does now allow directionless relationships, it does allow directionless querying which in turn provides the illusion of directionless relationships.

I've found producing many-to-many relationships between nodes a challenge in seraph-model. It would be a great feature to have.