/** * Add the constraints for a relationship count query. * * @param \Nova\Database\ORM\Builder $query * @param \Nova\Database\ORM\Builder $parent * @return \Nova\Database\ORM\Builder */ public function getRelationCountQuery(Builder $query, Builder $parent) { $query->select(new Expression('count(*)')); $otherKey = $this->wrap($query->getModel()->getTable() . '.' . $this->otherKey); return $query->where($this->getQualifiedForeignKey(), '=', new Expression($otherKey)); }
/** * Add the constraints for a relationship count query on the same table. * * @param \Nova\Database\ORM\Builder $query * @param \Nova\Database\ORM\Builder $parent * @return \Nova\Database\ORM\Builder */ public function getRelationCountQueryForSelfJoin(Builder $query, Builder $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 \Nova\Database\ORM\Builder $query * @param \Nova\Database\ORM\Builder $parent * @return \Nova\Database\ORM\Builder */ public function getRelationCountQuery(Builder $query, Builder $parent) { $query->select(new Expression('count(*)')); $key = $this->wrap($this->getQualifiedParentKeyName()); return $query->where($this->getHasCompareKey(), '=', new Expression($key)); }