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 7549529
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 30, 20262026-05-30T09:58:00+00:00 2026-05-30T09:58:00+00:00

I am using Doctrine 1.2 under the Zend framework to run my database queries.

  • 0

I am using Doctrine 1.2 under the Zend framework to run my database queries. I have two tables that I query using inner join, like so:

$q = Doctrine_Query::create()
    ->from('My_Model_MaterialsFromDb g')
    ->innerJoin('t.My_Model_TeachingMaterials t');
    ->where('g.id= ?', $id)
$result = $q->fetchArray();

Basically, the first table (materialsFromDb) contains a list of all of the teaching materials that I use for a lesson. The second one (teachingMaterials) has the details of the materials themselves.

When I run this query, here’s what the result invariably looks like:

Array
(
[0] => Array
    (
        [id] => 1
        [activityId] => 1
        [materialId] => 2
        [My_Model_Materials] => Array
            (
                [id] => 2
                [title] => My Groovy Material
                [materialType] => Worksheet
                [description] => This is my groovy material. It looks really cool.
                [filename] => Groovy Material.doc
                [uploaderId] => 1
                [uploadDate] => 2012-02-16
            )

    )
)

Is there any way I can run a doctrine query to “flatten” this to a single array? Is the result looking like this because both tables have a primary key called “id”? Having this multidimensional array as my result is a real pain to say the least.

  • 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-30T09:58:02+00:00Added an answer on May 30, 2026 at 9:58 am

    according to the Doctrine 1.2 docs, this is exaclty what’s supposed to happen.

    Doctrine hydration removes all duplicated data. It also performs many other things such as:
    
    Custom indexing of result set elements
    Value casting and preparation
    Value assignment listening
    Makes multi-dimensional array out of the two-dimensional result set array, the number of dimensions is equal to the number of nested joins
    Now consider the DQL equivalent of the SQL query we used:
    
    // test.php
    
    // ...
    
    
     $q = Doctrine_Query::create()
            ->select('u.id, u.username, p.phonenumber')
            ->from('User u')
            ->leftJoin('u.Phonenumbers p');
    
        $results = $q->execute(array(), Doctrine_Core::HYDRATE_ARRAY);
    
        print_r($results);
    The structure of this hydrated array would look like:
    
    $ php test.php
    Array
    (
        [0] => Array
            (
                [id] => 1
                [username] =>
                [Phonenumbers] => Array
                    (
                        [0] => Array
                            (
                                [id] => 1
                                [phonenumber] => 123 123
                            )
    
                        [1] => Array
                            (
                                [id] => 2
                                [phonenumber] => 456 123
                            )
    
                        [2] => Array
                            (
                                [id] => 3
                                [phonenumber] => 123 777
                            )
    
                    )
    
            )
        // ...
    )
    

    try…

    $result = $q->execute(array(), Doctrine_Core::HYDRATE_NONE);
    

    or…

    $result = $q->execute(array(), Doctrine_Core::HYDRATE_SCALAR);
    

    this one should return something like

    $user = array(
        'u_username' => 'jwage',
        'u_password' => 'changeme',
        // ...
    );
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I am using Doctrine 2 and Zend Framework 1.11. I have set up my
I'm using Doctrine 2 to try and do a query with an inner join.
I'm using Doctrine 1.2 as my ORM for a Zend Framework Project. I have
I've been working with Zend Framework (using Doctrine as the ORM) for quite a
I'm using Doctrine and want to log all generated SQL queries. I know that
I'm using Doctrine with Zend Framework. For my model, I'm using a base class,
I am using Doctrine ORM for php and Zend MVC. I have a mysql
I'm using Doctrine 2 in a Zend Framework application and require functionality similar to
I have recently started to learn using of Doctrine 2.0 framework for PHP. Now
I have been using doctrine with zend in a project without modules. It is

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.