Doctrine 1
  1. Doctrine 1
  2. DC-601

When using a join and giving an alias to each select column the hyrdrator only returns one row.

    Details

    • Type: Bug Bug
    • Status: Open
    • Priority: Major Major
    • Resolution: Unresolved
    • Affects Version/s: 1.2.2
    • Fix Version/s: None
    • Component/s: Query, Relations
    • Labels:
      None
    • Environment:
      XP Xamp

      Description

      Hi All
      I am running into a strange problem using Doctrine-1.2.2-- I have a multi row result set but only the first row of it is returned in the hyrdated array that is generated.
      I have tracked this down in the code to get a basic idea of whats going on – it seems that the $id variable in the hydrateResultSet function in Doctrine_Hydrator_Graph isn't being populated properly with data about the fields that are returning from my query. The _gatherRowData function seems to never detect that one of my columns is an identifier ("if ($cache[$key]['isIdentifier'])

      {" doesn't return true ever so the next line of code: "$id[$dqlAlias] .= '|' . $value;" doesn't run). I think this is the problem but I don't totally understand how the mapping process is taking place in this function so can't be absolutely sure. This hydration problem goes away if I don't use left joins in my query, or if I use a query where not every field I am requesting is assigned an alias (at least one of the fields doesn't use the 'as' syntax). For instance this php: {code}

      $q = Doctrine_Query::create();
      $q->from('Customer Customer');
      $q->leftJoin('Customer.Zip Zip');
      $q->addSelect('Customer.firstname as first_name');
      $q->addSelect('Customer.postalcode as postalcode');
      $q->setHydrationMode(Doctrine::HYDRATE_ARRAY);

      Generates this DQL: 
      

      SELECT Customer.firstname as first_name, Customer.postalcode as postalcode FROM Customer Customer LEFT JOIN Customer.Zip Zip

      And this SQL:
      

      SELECT c.firstname AS c_0, c.postalcode AS c_1 FROM customers c LEFT JOIN zips z ON c.postalcode = z.postalcode

      Which results in this return after hyrdration: 
      

      array('0'=>array('first_name'=>'Armando', 'postalcode'=>'00659'))

      However the following code hydrates just fine: 
      

      $q = Doctrine_Query::create();
      $q->from('Customer Customer');
      $q->addSelect('Customer.firstname as first_name');
      $q->setHydrationMode(Doctrine::HYDRATE_ARRAY);

      As does this code: 
      

      $q = Doctrine_Query::create();
      $q->from('Customer Customer');
      $q->leftJoin('Customer.Zip Zip');
      $q->addSelect('Customer.firstname');
      $q->addSelect('Customer.postalcode as postalcode');
      $q->setHydrationMode(Doctrine::HYDRATE_ARRAY);

      Here is the yaml for the sample data I am testing on: 
      

      detect_relations: false
      package: Example
      options:
      type: INNODB
      charset: utf8
      Customer:
      tableName: customers
      columns:
      customer_id:
      type: integer(4)
      primary: true
      notnull: true
      autoincrement: true
      firstname:
      type: string(45)
      lastname:
      type: string(45)
      streetaddress:
      type: string(45)
      city:
      type: string(45)
      state:
      type: string(45)
      postalcode:
      type: string(45)
      relations:
      Order:
      type: many
      local: customer_id
      foreign: customer_id
      Zip:
      type: one
      local: postalcode
      foreign: postalcode
      options:
      type: InnoDB
      Zip:
      connection: default_schema
      tableName: zips
      columns:
      postalcode:
      type: varchar(30)
      primary: true
      latitude: 'float(10,6)'
      longitude: 'float(10,6)'
      city: string(50)
      state: string(50)
      country: string(50)
      type: string(50)
      relations:
      Customer:
      type: many
      local: postalcode
      foreign: postalcode

      
      

      Perhaps there is something simple I am overlooking. To get around this I am just always selecting the primary key from my main table in every query.

      Thanks in advance for any advice.
      Will Ferrer

        Activity

          People

          • Assignee:
            Guilherme Blanco
            Reporter:
            will ferrer
          • Votes:
            2 Vote for this issue
            Watchers:
            3 Start watching this issue

            Dates

            • Created:
              Updated: