Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 1035515
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 16, 20262026-05-16T14:33:15+00:00 2026-05-16T14:33:15+00:00

I can’t find a way to set the default hydrator in Doctrine. It should

  • 0

I can’t find a way to set the default hydrator in Doctrine. It should be available. Right?

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

The above documentation page explains how to create a custom hydrator. The drawback here is that you need to “specify” the hydrator each and every time you execute a query.

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-16T14:33:15+00:00Added an answer on May 16, 2026 at 2:33 pm

    I figured this out by reading Chris Gutierrez’s comment and changing some stuff.

    First, define an extension class for Doctrine_Query. Extend the constructor to define your own hydration mode.

    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
            }
        }
    }
    

    Then, in your bootstrap, tell Doctrine about your new class.

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

    Chris Gutierrez defined the attribute for the connection instead of globally but I have more than one connection and I want to use this default for all of them.

    Now you don’t have to call Doctrine_Query::setHydrationMode() every time you build a query.

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

    EDIT: Changes below

    I have found a problem with the above. Specifically, doing something like “Doctrine_Core::getTable(‘Model’)->find(1)” will always return a hydrated array, not an object. So I have altered this a bit, defining custom execute methods for use in a Query call.

    Also, I added memory freeing code.

    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;
        }
    }
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

Can I change the field public virtual ClassOne ClassOne { get; set; } to
Can we change the default action of the edit selected row button? Here is
Can anyone enlighten me to a way I can Highlight the content of an
Can anybody help me? What should be the datatype for this type -07:00:00 of
Can anybody tell what is the best(easy) way to sort the following string 'index'
Can't figure out how to do this in a pretty way : I have
Can't work out a way to make an array of buttons in android. This
Can anyone (maybe an XSL-fan?) help me find any advantages with handling presentation of
can you recommend some good ASP.NET tutorials or a good book? Should I jump
I would like my Web page http://www.gmarks.org/math_in_e-mail.txt on my Apache 2.2.14 server to display

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.