src/orm/classes/Field/Entities.php
public function evaluateVirtualValue(ORM_Entity $entity)
    {
        if ($entity->getPrimaryKey())
        {
            $table = $this->table->getDriver()->getManager()
                ->getTableByEntityClass($this->getParam('class'));
            if (is_null($table))
            {
                return array();
            }
            $referenceField = $this->getParam('reference');
            $columns = $table->getColumns();
            if (!array_key_exists($referenceField, $columns))
            {
                throw new LogicException(sprintf('Unknown reference column: %s', $referenceField));
            }
            if (!$columns[$referenceField]->canBeUsedInWhere())
            {
                throw new LogicException(
                    sprintf('Field "%s" can not be used as a reference field', $referenceField));
            }
            $q = $table->createSelectQuery();

            /* Формируем условие выборки */
            $where = array($q->expr->eq($referenceField,
                $q->bindValue($entity->getPrimaryKey(), ":$referenceField",
                    $columns[$referenceField]->getPdoType())));

            if ($this->hasParam('filter'))
            {
                foreach ($this->getParam('filter') as $filter)
                {
                    $where []= call_user_func(array($q->expr, $filter[1]), $filter[0], $filter[2]);
                }
            }
            $q->where($where);

            /* Задаём сортировку */
            if ($this->hasParam('orderBy'))
            {
                $pairs = array_chunk($this->getParam('orderBy'), 2);
                foreach ($pairs as $pair)
                {
                    $q->orderBy(reset($pair), next($pair));
                }
            }

            return $table->loadFromQuery($q);
        }
        else
        {
            return new ORM_Entity_Collection();
        }
    }
public function evaluateVirtualValue(ORM_Entity $entity)
    {
        if ($entity->getPrimaryKey())
        {
            $table = $this->table->getDriver()->getManager()
                ->getTableByEntityClass($this->getParam('class'));
            if (is_null($table))
            {
                return array();
            }
            $referenceField = $this->getParam('reference');
            $columns = $table->getColumns();
            if (!array_key_exists($referenceField, $columns))
            {
                throw new LogicException(sprintf('Unknown reference column: %s', $referenceField));
            }
            if (!$columns[$referenceField]->canBeUsedInWhere())
            {
                throw new LogicException(
                    sprintf('Field "%s" can not be used as a reference field', $referenceField));
            }
            $q = $table->createSelectQuery();

            /* Формируем условие выборки */
            $where = array($q->expr->eq($referenceField,
                $q->bindValue($entity->getPrimaryKey(), ":$referenceField",
                    $columns[$referenceField]->getPdoType())));

            if ($this->hasParam('filter'))
            {
                foreach ($this->getParam('filter') as $filter)
                {
                    $where []= call_user_func(array($q->expr, $filter[1]), $filter[0], $filter[2]);
                }
            }
            $q->where($where);

            /* Задаём сортировку */
            if ($this->hasParam('orderBy'))
            {
                $pairs = array_chunk($this->getParam('orderBy'), 2);
                foreach ($pairs as $pair)
                {
                    $q->orderBy(reset($pair), next($pair));
                }
            }

            return $table->loadFromQuery($q);
        }
        else
        {
            return new ORM_Entity_Collection();
        }
    }
Вычисляет и возвращает значение виртуального поля

@param ORM_Entity $entity

@throws LogicException

@return mixed

@since 3.00