jadell / neo4jphp

PHP wrapper of the Neo4j REST interface
Other
532 stars 137 forks source link

Relation direction #134

Closed mkevenaar closed 10 years ago

mkevenaar commented 10 years ago

It would be nice to be able to know in a Relationship object what the direction of this relationship is.

Example:

$Index = new NodeIndex($client, 'node_auto_index');
$Node = $Index->findOne($key, addslashes('neo'));
$Node->getRelationships(array(),Relationship::DirectionAll);
if(count($Relations)){
    foreach($Relations as $Relation)
    {
        //How do I know here if I need start or end node?
        //would be nice if I could do:
        if($Relation->direction == Relationship::DirectionIn)
        {       
            //I need startnode
        } // and so on..
    }
}
jadell commented 10 years ago

Will this work?

if ($relation->getStartNode()->getId() == $node->getId()) {
    // $relation is outgoing from $node
} else {
    // $relation is incoming to $node
}
mkevenaar commented 10 years ago

that would work for now.

are you going to add this functionality in the Relationship object?

jadell commented 10 years ago

No. Asking for $relationship->direction doesn't make sense, because the answer changes depending on context, i. e. you can only ask what direction a relationship is from a specific node. A relationship doesn't have direction on it's own, so asking the relationship for its direction is meaningless.

If you want to know what direction a relationship is from a specific node, the only way to do that is to compare the node to either the start or end node of the relationship.

What problem are you trying to solve? Maybe there is another way to do it.