/** * Get the direction of a relationship out of a Relation instance. * * @param \Everyman\Neo4j\Relationship $relation * @param \Vinelab\NeoEloquent\Eloquent\Model $parent * @param \Vinelab\NeoEloquent\Eloquent\Model $related * @return string Either 'in' or 'out' */ public function directionFromRelation(Relationship $relation, Model $parent, Model $related) { // We will match the ids of the parent model and the start node of the relationship // and if they match we know that the direction is outgoing, incoming otherwise. $node = $relation->getStartNode(); // We will start by considering the relationship direction to be 'incoming' until // we match and find otherwise. $direction = 'in'; if ($node->getId() === $parent->getKey()) { $direction = 'out'; } return $direction; }
/** * Convert a model to a Node object. * * @param \Vinelab\NeoEloquent\Eloquent\Model $model * @return \Everyman\Neo4j\Node */ public function asNode(Model $model) { $node = $this->client->makeNode(); // If the key name of the model is 'id' we will need to set it properly with setId() // since setting it as a regular property with setProperty() won't cut it. if ($model->getKeyName() == 'id') { $node->setId($model->getKey()); } else { $node->setProperty($model->getKeyName(), $model->getKey()); } return $node; }