Esempio n. 1
0
 /**
  * Set a given relationship on this relation.
  *
  * @param \\Orientdb\Relationship $relation
  */
 public function setRelation(Relationship $relation, $debug = false)
 {
     // Set the relation object.
     $this->relation = $relation;
     // Replace the attributes with those brought from the given relation.
     $this->attributes = $relation->getProperties();
     //$this->setAttribute($this->primaryKey, $relation->getId());
     // Set the start and end nodes.
     $this->start = $relation->getStartNode();
     $this->end = $relation->getEndNode();
     // Instantiate and fill out the related model.
     $relatedNode = $this->isDirectionOut() ? $this->end : $this->start;
     $attributes = array_merge(['id' => $relatedNode->getId()], $relatedNode->getProperties());
     // This is an existing relationship.
     $exists = true;
     $this->related = $this->related->newFromBuilder($attributes, $exists);
     $this->related->setConnection($this->related->getConnection());
 }
Esempio n. 2
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;
 }
Esempio n. 3
0
 /**
  * Add a relationship MATCH clause to the query.
  *
  * @param  \Sgpatil\Orientdb\Eloquent\Model $parent       The parent model of the relationship
  * @param  \Sgpatil\Orientdb\Eloquent\Model $related      The related model
  * @param  string $relatedNode  The related node' placeholder
  * @param  string $relationship The relationship title
  * @param  string $property     The parent's property we are matching against
  * @param  string $value
  * @param  string $direction Possible values are in, out and in-out
  * @return \Sgpatil\Orientdb\Query\Builder|static
  */
 public function matchRelation($parent, $related, $relatedNode, $relationship, $property, $value = null, $direction = 'out')
 {
     $parentLabels = $parent->getTable();
     $relatedLabels = $related->getTable();
     $parentNode = $this->modelAsNode($parentLabels);
     $this->matches[] = array('type' => 'Relation', 'property' => $property, 'direction' => $direction, 'relationship' => $relationship, 'parent' => array('node' => $parentNode, 'labels' => $parentLabels), 'related' => array('node' => $relatedNode, 'labels' => $relatedLabels));
     $this->addBinding(array($this->wrap($property) => $value), 'matches');
     return $this;
 }
 /**
  * Bootstrap the application events.
  *
  * @return void
  */
 public function boot()
 {
     Model::setConnectionResolver($this->app['db']);
     Model::setEventDispatcher($this->app['events']);
     $this->package('sgpatil/orientdb');
 }
Esempio n. 5
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;
 }