getQualifiedKeyName() public method

Get the table qualified key name.
public getQualifiedKeyName ( ) : string
return string
Ejemplo n.º 1
0
 /**
  * Find a model by its primary key.
  *
  * @param  array  $id
  * @param  array  $columns
  * @return \Illuminate\Database\Eloquent\Model|Collection|static
  */
 public function findMany($id, $columns = array('*'))
 {
     if (empty($id)) {
         return $this->model->newCollection();
     }
     $this->query->whereIn($this->model->getQualifiedKeyName(), $id);
     return $this->get($columns);
 }
Ejemplo n.º 2
0
 protected function checkQueryGroupBy()
 {
     $groups = $this->query->getQuery()->groups;
     $keyGroup = $this->model->getQualifiedKeyName();
     if (empty($groups) || !in_array($keyGroup, $groups)) {
         $this->query->groupBy($keyGroup);
     }
 }
Ejemplo n.º 3
0
 /**
  * Add a where clause on the primary key to the query.
  *
  * @param  mixed  $id
  * @return $this
  */
 public function whereKey($id)
 {
     if (is_array($id)) {
         $this->query->whereIn($this->model->getQualifiedKeyName(), $id);
         return $this;
     }
     return $this->where($this->model->getQualifiedKeyName(), '=', $id);
 }
 /**
  * Apply the scope to a given Eloquent query builder.
  *
  * @param  \Illuminate\Database\Eloquent\Builder  $builder
  * @param  \Illuminate\Database\Eloquent\Model  $model
  * @return void
  */
 public function apply(Builder $builder, Model $model)
 {
     $builder->join($model->getVersionTable(), function ($join) use($model) {
         $join->on($model->getQualifiedKeyName(), '=', $model->getQualifiedVersionKeyName());
         $join->on($model->getQualifiedVersionColumn(), '=', $model->getQualifiedLatestVersionColumn());
     });
     $this->extend($builder);
 }
Ejemplo n.º 5
0
 /**
  * Execute a callback over each item while chunking.
  *
  * @param  callable  $callback
  * @param  int  $count
  * @return bool
  */
 public function each(callable $callback, $count = 1000)
 {
     if (is_null($this->query->orders) && is_null($this->query->unionOrders)) {
         $this->orderBy($this->model->getQualifiedKeyName(), 'asc');
     }
     return $this->chunk($count, function ($results) use($callback) {
         foreach ($results as $key => $value) {
             if ($callback($value, $key) === false) {
                 return false;
             }
         }
     });
 }
Ejemplo n.º 6
0
 /**
  * @param JoinClause $query
  * @param array $constraints
  *
  * @throws \InvalidArgumentException
  */
 private function generateJoinConstraints($query, $constraints)
 {
     foreach ($constraints as $constraint) {
         if (empty($constraint)) {
             continue;
         } elseif (is_array($constraint)) {
             $constraint[2] = array_key_exists(2, $constraint) ? $constraint[2] : '=';
             $this->transformCustomConstraint($query, $constraint[0], $constraint[1], $constraint[2]);
         } elseif ($constraint instanceof Model) {
             $query->where($constraint->getQualifiedKeyName(), '=', $constraint->getKey());
         } elseif ($constraint instanceof Collection) {
             $query->whereIn($constraint->first()->getQualifiedKeyName(), $constraint->modelKeys());
         } elseif ($constraint instanceof \Closure) {
             call_user_func($constraint, $query);
         } elseif (is_int((int) $constraint)) {
             $query->where($this->related->getQualifiedKeyName(), '=', $constraint);
         } else {
             throw new \InvalidArgumentException('Join constraint is not an object.', 500);
         }
     }
 }
 /**
  * Get the key for comparing against the parent key in "has" query.
  *
  * @return string
  */
 public function getHasCompareKey()
 {
     return $this->farParent->getQualifiedKeyName();
 }
Ejemplo n.º 8
0
 /**
  * Get the fully qualified parent key name.
  *
  * @return string
  */
 public function getQualifiedParentKeyName()
 {
     return $this->parent->getQualifiedKeyName();
 }
 /**
  * Get the key name to use when querying for records.
  *
  * If no key name has been specified for the model, `Model::getQualifiedKeyName()` will be used as the
  * default.
  *
  * @param Model $model
  * @param $resourceType
  * @return string
  */
 protected function resolveQualifiedKeyName(Model $model, $resourceType)
 {
     return isset($this->keyNames[$resourceType]) ? sprintf('%s.%s', $model->getTable(), $this->keyNames[$resourceType]) : $model->getQualifiedKeyName();
 }
Ejemplo n.º 10
0
 /**
  * Join pivot or 'through' table.
  *
  * @param  \Illuminate\Database\Eloquent\Model $parent
  * @param  \Illuminate\Database\Eloquent\Relations\Relation $relation
  * @param  string $type
  * @return void
  */
 protected function joinIntermediate(Model $parent, Relation $relation, $type)
 {
     if ($relation instanceof BelongsToMany) {
         $table = $relation->getTable();
         $fk = $relation->getForeignKey();
     } else {
         $table = $relation->getParent()->getTable();
         $fk = $table . '.' . $parent->getForeignKey();
     }
     $pk = $parent->getQualifiedKeyName();
     if (!$this->alreadyJoined($join = (new Join($type, $table))->on($fk, '=', $pk))) {
         $this->query->joins[] = $join;
     }
 }
 /**
  * Get the fully qualified parent key naem.
  *
  * @return string
  */
 protected function getQualifiedParentKeyName()
 {
     return $this->parent->getQualifiedKeyName();
 }
Ejemplo n.º 12
0
 /**
  * Add a generic "order by" clause if the query doesn't already have one.
  *
  * @return void
  */
 protected function enforceOrderBy()
 {
     if (empty($this->query->orders) && empty($this->query->unionOrders)) {
         $this->orderBy($this->model->getQualifiedKeyName(), 'asc');
     }
 }
Ejemplo n.º 13
0
 /**
  * Add the constraints for a relationship count query.
  *
  * @param  \Illuminate\Database\Eloquent\Builder  $query
  * @return \Illuminate\Database\Eloquent\Builder
  */
 public function getRelationCountQuery(Builder $query)
 {
     $query->select(new Expression('count(*)'));
     $key = $this->wrap($this->parent->getQualifiedKeyName());
     return $query->where($this->getForeignKey(), '=', new Expression($key));
 }
 /**
  * {@inheritdoc}
  */
 protected function getKeyName()
 {
     return $this->model->getQualifiedKeyName();
 }