/** * 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)); }