/** * Add the only-trashed extension to the builder. * * @param \Analogue\ORM\System\Query $query * @return void */ protected function addOnlyTrashed(Query $query) { $query->macro('onlyTrashed', function (Query $query) { $this->remove($query); $query->getQuery()->whereNotNull($query->getMapper()->getEntityMap()->getQualifiedDeletedAtColumn()); return $query; }); }
/** * Set the keys for a save update query. * * @param \Analogue\ORM\Query $query * @return \Analogue\ORM\Query */ protected function setKeysForSaveQuery(Query $query) { $query->where($this->morphType, $this->morphClass); return parent::setKeysForSaveQuery($query); }
/** * Add the constraints for a relationship count query on the same table. * * @param \Analogue\ORM\Query $query * @param \Analogue\ORM\Query $parent * @return \Analogue\ORM\Query */ public function getRelationCountQueryForSelfJoin(Query $query, Query $parent) { $query->select(new Expression('count(*)')); $tablePrefix = $this->query->getQuery()->getConnection()->getTablePrefix(); $query->from($this->table . ' as ' . $tablePrefix . ($hash = $this->getRelationCountHash())); $key = $this->wrap($this->getQualifiedParentKeyName()); return $query->where($hash . '.' . $this->foreignKey, '=', new Expression($key)); }
/** * Add the constraints for a relationship count query. * * @param \Analogue\ORM\System\Query $query * @param \Analogue\ORM\System\Query $parent * @return \Analogue\ORM\System\Query */ public function getRelationCountQuery(Query $query, Query $parent) { $query->select(new Expression('count(*)')); $otherKey = $this->wrap($query->getTable() . '.' . $this->otherKey); return $query->where($this->getQualifiedForeignKey(), '=', new Expression($otherKey)); }
/** * Merge the "wheres" from a relation query to a has query. * * @param \Analogue\ORM\System\Query $hasQuery * @param \Analogue\ORM\Relationships\Relationship $relation * @return void */ protected function mergeWheresToHas(Query $hasQuery, Relationship $relation) { // Here we have the "has" query and the original relation. We need to copy over any // where clauses the developer may have put in the relationship function over to // the has query, and then copy the bindings from the "has" query to the main. $relationQuery = $relation->getBaseQuery(); $hasQuery->mergeWheres($relationQuery->wheres, $relationQuery->getBindings()); $this->query->mergeBindings($hasQuery->getQuery()); }
/** * Add the constraints for a relationship count query. * * @param \Analogue\ORM\System\Query $query * @param \Analogue\ORM\System\Query $parent * @return \Analogue\ORM\System\Query */ public function getRelationCountQuery(Query $query, Query $parent) { $query->select(new Expression('count(*)')); $key = $this->wrap($this->getQualifiedParentKeyName()); return $query->where($this->getHasCompareKey(), '=', new Expression($key)); }