How to set the default hydrator in Doctrine?

I cannot find a way to set the default hydrator in Doctrine. It must be available. Correctly?

http://docs.doctrine-project.org/projects/doctrine1/en/latest/en/manual/data-hydrators.html#writing-hydration-method

The documentation page above explains how to create your own hydrator. The disadvantage here is that you need to β€œindicate” the hydrator every time you execute a request.

+3
source share
2 answers

I realized this by reading Chris Gutierrez's comment and changing some things.

Doctrine_Query. , .

class App_Doctrine_Query extends Doctrine_Query
{
    public function __construct(Doctrine_Connection $connection = null,
        Doctrine_Hydrator_Abstract $hydrator = null)
    {
        parent::__construct($connection, $hydrator);
        if ($hydrator === null) {
            $this->setHydrationMode(Doctrine::HYDRATE_ARRAY); // I use this one the most
        }
    }
}

, , .

Doctrine_Manager::getInstance()->setAttribute(Doctrine_Core::ATTR_QUERY_CLASS, 'App_Doctrine_Query');  

Chris Gutierrez , , , .

Doctrine_Query:: setHydrationMode() , .


http://www.doctrine-project.org/projects/orm/1.2/docs/manual/configuration/en#configure-query-class

EDIT:

. , - Doctrine_Core:: getTable ('Model') β†’ find (1) " , . , .

, .

class App_Doctrine_Query extends Doctrine_Query
{
    public function rows($params = array(), $hydrationMode = null)
    {
        if ($hydrationMode === null)
            $hydrationMode = Doctrine_Core::HYDRATE_ARRAY;
        $results = parent::execute($params, $hydrationMode);
        $this->free(true);
        return $results;
    }

    public function row($params = array(), $hydrationMode = null)
    {
        if ($hydrationMode === null)
            $hydrationMode = Doctrine_Core::HYDRATE_ARRAY;
        $results = parent::fetchOne($params, $hydrationMode);
        $this->free(true);
        return $results;
    }
}
+2

, , , , Doctrine. , , , :

Doctrine_Query::create() , Doctrine_Query_Abstract::__construct(), - . . , Doctrine_Hydrator, , Doctrine::HYDRATE_RECORD.

, Doctrine_Query factory ?

public static function create($conn = null)
{
    return new Doctrine_Query($conn,Doctrine::HYDRATE_ARRAY);
}
0

Source: https://habr.com/ru/post/1728460/


All Articles