src/orm/classes/Field/Bindings.php
public function evaluateVirtualValue(ORM_Entity $entity)
    {
        if ($entity->getPrimaryKey())
        {
            $table = $this->getBindingsTable();

            $q = Eresus_DB::getHandler()->createSelectQuery();
            $q->select($this->getName());
            $q->from($table->getName());
            $q->where(
                $q->expr->eq(
                    preg_replace('/^.*?_/', '', $entity->getTable()->getName()),
                    $q->bindValue($entity->getPrimaryKey())
                ));
            $bindings = $q->fetchAll();
            $targetIds = array();
            foreach ($bindings as $binding)
            {
                $targetIds [] = $binding[$this->getName()];
            }
            if (count($targetIds) == 0)
            {
                return new ORM_Entity_Collection();
            }
            $targetTable = $this->table->getDriver()->getManager()
                ->getTableByEntityClass($this->getParam('class'));
            if (is_null($targetTable))
            {
                return new ORM_Entity_Collection();
            }
            $q = $targetTable->createSelectQuery();
            $q->where($q->expr->in($targetTable->getPrimaryKey(), $targetIds));
            return $targetTable->loadFromQuery($q);
        }
        else
        {
            return new ORM_Entity_Collection();
        }
    }
public function evaluateVirtualValue(ORM_Entity $entity)
    {
        if ($entity->getPrimaryKey())
        {
            $table = $this->getBindingsTable();

            $q = Eresus_DB::getHandler()->createSelectQuery();
            $q->select($this->getName());
            $q->from($table->getName());
            $q->where(
                $q->expr->eq(
                    preg_replace('/^.*?_/', '', $entity->getTable()->getName()),
                    $q->bindValue($entity->getPrimaryKey())
                ));
            $bindings = $q->fetchAll();
            $targetIds = array();
            foreach ($bindings as $binding)
            {
                $targetIds [] = $binding[$this->getName()];
            }
            if (count($targetIds) == 0)
            {
                return new ORM_Entity_Collection();
            }
            $targetTable = $this->table->getDriver()->getManager()
                ->getTableByEntityClass($this->getParam('class'));
            if (is_null($targetTable))
            {
                return new ORM_Entity_Collection();
            }
            $q = $targetTable->createSelectQuery();
            $q->where($q->expr->in($targetTable->getPrimaryKey(), $targetIds));
            return $targetTable->loadFromQuery($q);
        }
        else
        {
            return new ORM_Entity_Collection();
        }
    }
Вычисляет и возвращает значение виртуального поля

@param ORM_Entity $entity

@return mixed

@since 3.00