Example #1
0
 /**
  * Get the direction of a relationship out of a Relation instance.
  *
  * @param  \\Orientdb\Relationship $relation
  * @param  \Sgpatil\Orientdb\Eloquent\Model        $parent
  * @param  \Sgpatil\Orientdb\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;
 }
Example #2
0
 /**
  * Convert a model to a Node object.
  *
  * @param  \Sgpatil\Orientdb\Eloquent\Model $model
  * @return \\Orientdb\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;
 }