public function annotate()
    {
        $args = static::formatConditions(__METHOD__, func_get_args());

        $names = $this->_fields;
        if (is_null($this->_fields)) {
            $names = [];
            foreach ($this->model->getMeta()->getFields() as $field) {
                $names[] = $field->getName();
            }
        }
        $clone = $this->_clone();
        foreach ($args as $alias => $arg) {
            if (in_array($alias, $names)) {
                throw new ValueError(
                    sprintf("The annotation '%s' conflicts with a field on the model.", $alias)
                );
            }
            $clone->query->addAnnotation(['annotation' => $arg, 'alias' => $alias, 'isSummary' => false]);
        }

        foreach ($clone->query->annotations as $alias => $annotation) {
            if ($annotation->containsAggregates() && array_key_exists($alias, $args)) {
                if (is_null($clone->_fields)) {
                    $clone->query->groupBy = true;
                } else {
                    $clone->query->setGroupBy();
                }
            }
        }

        return $clone;
    }
public function annotate()
    {
        $args = static::formatConditions(__METHOD__, func_get_args());

        $names = $this->_fields;
        if (is_null($this->_fields)) {
            $names = [];
            foreach ($this->model->getMeta()->getFields() as $field) {
                $names[] = $field->getName();
            }
        }
        $clone = $this->_clone();
        foreach ($args as $alias => $arg) {
            if (in_array($alias, $names)) {
                throw new ValueError(
                    sprintf("The annotation '%s' conflicts with a field on the model.", $alias)
                );
            }
            $clone->query->addAnnotation(['annotation' => $arg, 'alias' => $alias, 'isSummary' => false]);
        }

        foreach ($clone->query->annotations as $alias => $annotation) {
            if ($annotation->containsAggregates() && array_key_exists($alias, $args)) {
                if (is_null($clone->_fields)) {
                    $clone->query->groupBy = true;
                } else {
                    $clone->query->setGroupBy();
                }
            }
        }

        return $clone;
    }
public function annotate ( ) { $ args = static :: formatConditions ( __METHOD__ , func_get_args ( ) ) ; $ names = $ this -> _fields ; if ( is_null ( $ this -> _fields ) ) { $ names = [ ] ; foreach ( $ this -> model -> getMeta ( ) -> getFields ( ) as $ field ) { $ names [ ] = $ field -> getName ( ) ; } } $ clone = $ this -> _clone ( ) ; foreach ( $ args as $ alias => $ arg ) { if ( in_array ( $ alias , $ names ) ) { throw new ValueError ( sprintf ( "The annotation '%s' conflicts with a field on the model." , $ alias ) ) ; } $ clone -> query -> addAnnotation ( [ 'annotation' => $ arg , 'alias' => $ alias , 'isSummary' => false ] ) ; } foreach ( $ clone -> query -> annotations as $ alias => $ annotation ) { if ( $ annotation -> containsAggregates ( ) && array_key_exists ( $ alias , $ args ) ) { if ( is_null ( $ clone -> _fields ) ) { $ clone -> query -> groupBy = true ; } else { $ clone -> query -> setGroupBy ( ) ; } } } return $ clone ; }
Return a query set in which the returned objects have been annotated
with extra data or aggregations.

@return Queryset

@throws InvalidArgumentException
@throws ValueError

@since  1.1.0

@author Eddilbert Macharia (http://eddmash.com) <edd.cowan@gmail.com>
Return a query set in which the returned objects have been annotated with extra data or aggregations .