Inheritance: extends Illuminate\Database\Eloquent\Relations\Relation
Ejemplo n.º 1
7
 /**
  * @param QueryBuilder $builder
  * @param $data
  *
  * @return void
  */
 public function applyFilterConstraint(QueryBuilder $builder, $data)
 {
     if (empty($data)) {
         return;
     }
     $builder->whereIn($this->relation->getForeignKey(), explode(',', $data));
 }
Ejemplo n.º 2
3
 public function __construct(Builder $query, Model $parent, $foreignKey, $otherKey, $relationName)
 {
     $this->relationName = $relationName;
     parent::__construct($query, $parent, $foreignKey, $otherKey, $relationName);
 }
Ejemplo n.º 3
2
 protected function joinBelongsToRelation(Relations\BelongsTo $relation, $type)
 {
     $table = $relation->getRelated()->getTable();
     $foreignKey = $relation->getQualifiedForeignKey();
     $localKey = $relation->getQualifiedOtherKeyName();
     $this->query->join($table, $foreignKey, '=', $localKey, $type);
 }
Ejemplo n.º 4
2
 public static function setBelongsTo(BelongsTo $belongsTo, $object = null)
 {
     return $object ? $belongsTo->associate($object) : $belongsTo->dissociate();
 }
Ejemplo n.º 5
2
 /**
  * Add select with alias to query from "belongs to" relation
  *
  * @param Builder   $query
  * @param BelongsTo $relatedModel
  */
 private function addBelongsToSelect(Builder $query, BelongsTo $relatedModel)
 {
     $query->getQuery()->join($relatedModel->getRelated()->getTable(), $relatedModel->getQualifiedForeignKey(), '=', $relatedModel->getQualifiedOtherKeyName());
 }
Ejemplo n.º 6
2
 protected function applyBelongsTo(Query $query, Model $model, BelongsTo $belongsTo, $name)
 {
     if (isset($this->joinClasses[$name])) {
         return;
     }
     $modelTable = '';
     // If the table has already an alias
     if (str_contains($name, '.')) {
         $path = explode('.', $name);
         array_pop($path);
         $parentPath = implode('.', $path);
         if (isset($this->joinAliases[$parentPath])) {
             $modelTable = $this->joinAliases[$parentPath];
         }
     }
     if (!$modelTable) {
         $modelTable = $belongsTo->getParent()->getTable();
     }
     $related = $belongsTo->getRelated();
     $relatedTable = $related->getTable();
     $foreignKey = $belongsTo->getForeignKey();
     $otherKey = $belongsTo->getOtherKey();
     $alias = $this->joinNameToAlias($name);
     $joinMethod = $this->getJoinMethod($name);
     $query->{$joinMethod}("{$relatedTable} AS {$alias}", "{$modelTable}.{$foreignKey}", '=', "{$alias}.{$otherKey}");
     $query->distinct();
     $this->addQueryColumn("{$modelTable}.{$foreignKey}");
     $this->joinClasses[$name] = $belongsTo->getRelated();
     $this->joinTable[$name] = $relatedTable;
     $this->joinAliases[$name] = $alias;
 }
Ejemplo n.º 7
1
 /**
  * Add an object through a BelongsTo relation
  *
  * @param \Illuminate\Database\Eloquent\Relations\BelongsTo $relation
  * @param \Illuminate\Database\Eloquent\Model $model
  * @return bool
  */
 protected function addBelongsToAssociatedObject(BelongsTo $relation, \Illuminate\Database\Eloquent\Model $model)
 {
     $relation->associate($model);
     return $this->save();
 }
Ejemplo n.º 8
1
 /**
  * Makes a raw where condition string from a BelongsTo relation instance.
  *
  * @param BelongsTo $relation
  * @return string
  */
 protected function getConditionStringFromBelongsTo(BelongsTo $relation)
 {
     $id = $this->getAttribute($relation->getForeignKey());
     // an empty foreign key will, as a null-scope, remove the item from any list
     if (null === $id) {
         return null;
     }
     return '`' . $relation->getForeignKey() . '` = ' . (int) $id;
 }
Ejemplo n.º 9
0
 /**
  * Create a new belongs to relationship instance.
  *
  * @param  \Illuminate\Database\Eloquent\Builder  $query
  * @param  \Illuminate\Database\Eloquent\Model  $parent
  * @param  string  $foreignKey
  * @param  string  $otherKey
  * @param  string  $type
  * @param  string  $relation
  * @return void
  */
 public function __construct(Builder $query, Model $parent, $foreignKey, $otherKey, $type, $relation)
 {
     $this->morphType = $type;
     parent::__construct($query, $parent, $foreignKey, $otherKey, $relation);
 }
Ejemplo n.º 10
0
 /**
  * Handle dynamic method calls to the relationship.
  *
  * @param string $method
  * @param array  $parameters
  *
  * @return mixed
  */
 public function __call($method, $parameters)
 {
     $result = parent::__call($method, $parameters);
     if ($method !== 'get') {
         call_user_func_array([$this->fallbackQuery, $method], $parameters);
     }
     return $result;
 }
Ejemplo n.º 11
0
 private function generateNullConditionFromBelongsTo(BelongsTo $relation)
 {
     $this->query = $this->query->whereNull($relation->getQualifiedOtherKeyName());
 }
Ejemplo n.º 12
0
 /**
  * Handle dynamic method calls to the relationship.
  *
  * @param  string  $method
  * @param  array   $parameters
  * @return mixed
  */
 public function __call($method, $parameters)
 {
     try {
         return parent::__call($method, $parameters);
     } catch (BadMethodCallException $e) {
         $this->macroBuffer[] = compact('method', 'parameters');
         return $this;
     }
 }