Add a counter for a relation.

@param string $alias
@param string $field
@param \Closure $scope
@return $this
506990
public function track($alias, $field, Closure $scope = null) {
        $this->_counters[$alias] = [
            'field' => $field,
            'scope' => $scope
        ];

        return $this;
    }
823780
public function field($field, $alias = null) {
        if (is_string($field)) {
            $fields = explode(',', trim($field));
            foreach ($fields as $field) {
                $this->fields [] = Condition::cleanField($field . ($alias ? ' AS ' . $alias : ''));
            }
        } else if ($field instanceof Query) {
            if ($alias) {
                $field->alias($alias);
            }
            $this->fields [] = $field;
        } else if ($field instanceof ImmutableValue) {
            if ($alias) {
                $field->alias($alias);
            }
            $this->fields [] = $field;
        }

        return $this;
    }
319677
public function orderByMultiple($order = array('_leftnode' => 'asc'), $alias = null)
    {
        if (true === empty($order)) {
            $order = array('_leftnode' => 'asc');
        }

        $this->resetDQLPart('orderBy');
        $alias = $this->getFirstAlias($alias);
        foreach ($order as $field => $sort) {
            if (0 < count($this->getDQLPart('orderBy'))) {
                $this->addOrderBy($alias.'.'.$field, $sort);
            } else {
                $this->orderBy($alias.'.'.$field, $sort);
            }
        }

        return $this;
    }
838874
public function count($column = '*', string $alias = null, bool $distinct = false): self
    {
        return $this->column((new Expression())->count($column, $distinct), $alias);
    }
1085532
public function count($column, $alias)
    {
        return $this->addSelectColumn(new Func\Count(new Expr\Column($column)), $alias);
    }
512880
public function addCount($column = '*', string $alias = null): self
    {
        return $this->addAggregate('COUNT', $column, $alias);
    }
676953
public function share( $alias, $definition ) {
		$this->define( $alias, $definition );

		if ( is_array( $alias ) ) {
			$alias = key( $alias );
		}

		$this->shared[ $alias ] = true;

		return $this;
	}
225689
public function sum($alias, $field = null, $script = null)
    {
        $aggregation = new SumAggregation($alias, $field, $script);

        $this->append($aggregation);
    }
308498
public function addCommand($callback, $alias = null, $default = false)
    {
        if ($alias instanceof \Closure && is_string($callback)) {
            list($alias, $callback) = array($callback, $alias);
        }
        if (is_array($callback) && is_string($callback[0])) {
            $callback = implode('::', $callback);
        }
        
        $name = '';
        if (is_string($callback)) {
            $name = $callback;
            if (is_callable($callback)) {
                if (strpos($callback, '::') !== false) {
                    list($classname, $methodname) = explode('::', $callback);
                    $name = Utils::dashized($methodname);
                } else {
                    $name = strtolower(trim(str_replace('_', '-', $name), '-'));
                }
            } else {
                if (substr($name, -7) === 'Command') {
                    $name = substr($name, 0, -7);
                }
                $name = Utils::dashized(basename(str_replace('\\', '/', $name)));
            }
        } else if (is_object($callback) && !($callback instanceof Closure)) {
            $classname = get_class($callback);
            if (!($callback instanceof Command)) {
                throw new ConsoleException("'$classname' must inherit from 'ConsoleKit\Command'");
            }
            if (substr($classname, -7) === 'Command') {
                $classname = substr($classname, 0, -7);
            }
            $name = Utils::dashized(basename(str_replace('\\', '/', $classname)));
        } else if (!$alias) {
            throw new ConsoleException("Commands using closures must have an alias");
        }

        $name = $alias ?: $name;
        $this->commands[$name] = $callback;
        if ($default) {
            $this->defaultCommand = $name;
        }
        return $this;
    }
357808
public function from(string $table, string $alias = null, $field = null): Select
    {
        $this->from[] = [
          'table' => $table,
          'alias' => $alias
        ];

        if ($field !== null) {
            if (is_array($field)) {
                foreach ($field as $fld) {
                    $this->field(($alias ?? $table) . '.' . $fld);
                }
            } else {
                $this->field(($alias ?? $table) . '.' . $field);
            }
        }

        return $this;
    }
131057
public function ref($name, $alias = "", $type = "field")
    {
        $this->addNewToSequence($type, $name, $alias);
        return $this;
    }
242740
public function hasMany(string $alias, string $entity): Relation {
    return $this->has_many[$entity] = new Relation($alias, $this->full_name, $entity);
  }
693926
public function addFieldRound($field, $decimals = 0, $alias = null)
    {
        $this->addField(new Func('round', $field, new Expression((int)$decimals)), $alias); return $this;
    }
1112072
public function fkAddOrderBy($field, $fkField, $order = 'ASC')
    {
        $alias = $this->tableAlias();
        $this->queryBuilder->join($this->getFullFieldName($field), $alias);
        $this->queryBuilder->addOrderBy($this->getFullFieldName($fkField, $alias), $order);

        return $this;
    }
133989
public function addField($field)
    {
        $entityFieldNames = array_flip($this->mappedFields);
        if (array_key_exists($field, $entityFieldNames)) {
            parent::addField($entityFieldNames[$field]);
        }

        return $this;
    }
509440
public function count(string $column = '*', string $alias = 'count'): ResultInterface
    {
        $this->aggregate['count'] = [$column, $alias];
        $this->addAggregateDecorator($alias);

        return $this->execute();
    }
143192
public function group($field, $prefixWithTableAlias = true)
    {
        $aliasInsert = $prefixWithTableAlias ? '?f:alias:.' : '';

        if ($this->groupSql == '') {
            $this->groupSql = " GROUP BY {$aliasInsert}?f";
        } else {
            $this->groupSql .= ", {$aliasInsert}?f";
        }
        $this->groupArguments[] = $field;
        return $this;
    }