Skip to content

Commit

Permalink
Merge branch 'hotfix/#1507-fixed-wrong-property-name-in-resultset-map…
Browse files Browse the repository at this point in the history
…ping-builder' into 2.5

Backport merge #1507 into 2.5.x
Close #1507
  • Loading branch information
Ocramius committed Nov 7, 2015
2 parents 2d1bc78 + 1eb9c8a commit 39098ce
Show file tree
Hide file tree
Showing 6 changed files with 86 additions and 2 deletions.
4 changes: 2 additions & 2 deletions lib/Doctrine/ORM/Query/ResultSetMappingBuilder.php
Original file line number Diff line number Diff line change
Expand Up @@ -438,8 +438,8 @@ public function generateSelectClause($tableAliases = array())
$sql .= $class->fieldMappings[$this->fieldMappings[$columnName]]['columnName'];
} else if (isset($this->metaMappings[$columnName])) {
$sql .= $this->metaMappings[$columnName];
} else if (isset($this->discriminatorColumn[$columnName])) {
$sql .= $this->discriminatorColumn[$columnName];
} else if (isset($this->discriminatorColumns[$dqlAlias])) {
$sql .= $this->discriminatorColumns[$dqlAlias];
}

$sql .= " AS " . $columnName;
Expand Down
25 changes: 25 additions & 0 deletions tests/Doctrine/Tests/Models/DDC3899/DDC3899Contract.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
<?php

namespace Doctrine\Tests\Models\DDC3899;

/**
* @Entity
* @Table(name="dc3899_contracts")
* @InheritanceType("SINGLE_TABLE")
* @DiscriminatorColumn(name="discr", type="string")
* @DiscriminatorMap({
* "fix" = "DDC3899FixContract",
* "flexible" = "DDC3899FlexContract"
* })
*/
abstract class DDC3899Contract
{
/** @Id @Column(type="integer") */
public $id;

/** @Column(type="boolean") */
public $completed = false;

/** @ManyToOne(targetEntity="DDC3899User", inversedBy="contract") */
public $user;
}
12 changes: 12 additions & 0 deletions tests/Doctrine/Tests/Models/DDC3899/DDC3899FixContract.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
<?php

namespace Doctrine\Tests\Models\DDC3899;

/**
* @Entity
*/
class DDC3899FixContract extends DDC3899Contract
{
/** @column(type="integer") */
public $fixPrice = 0;
}
15 changes: 15 additions & 0 deletions tests/Doctrine/Tests/Models/DDC3899/DDC3899FlexContract.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
<?php

namespace Doctrine\Tests\Models\DDC3899;

/**
* @Entity
*/
class DDC3899FlexContract extends DDC3899Contract
{
/** @column(type="integer") */
public $hoursWorked = 0;

/** @column(type="integer") */
public $pricePerHour = 0;
}
16 changes: 16 additions & 0 deletions tests/Doctrine/Tests/Models/DDC3899/DDC3899User.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
<?php

namespace Doctrine\Tests\Models\DDC3899;

/**
* @Entity
* @Table(name="dc3899_users")
*/
class DDC3899User
{
/** @Id @Column(type="integer") */
public $id;

/** @OneToMany(targetEntity="DDC3899Contract", mappedBy="user") */
public $contracts;
}
16 changes: 16 additions & 0 deletions tests/Doctrine/Tests/ORM/Functional/NativeQueryTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -791,4 +791,20 @@ public function testGenerateSelectClauseToString()

$this->assertSQLEquals('u.id AS id0, u.status AS status1, u.username AS username2, u.name AS name3, u.email_id AS email_id4', (string)$rsm);
}

/**
* @group DDC-3899
*/
public function testGenerateSelectClauseWithDiscriminatorColumn()
{
$rsm = new ResultSetMappingBuilder($this->_em, ResultSetMappingBuilder::COLUMN_RENAMING_INCREMENT);
$rsm->addEntityResult('Doctrine\Tests\Models\DDC3899\DDC3899User', 'u');
$rsm->addJoinedEntityResult('Doctrine\Tests\Models\DDC3899\DDC3899FixContract', 'c', 'u', 'contracts');
$rsm->addFieldResult('u', $this->platform->getSQLResultCasing('id'), 'id');
$rsm->setDiscriminatorColumn('c', $this->platform->getSQLResultCasing('discr'));

$selectClause = $rsm->generateSelectClause(array('u' => 'u1', 'c' => 'c1'));

$this->assertSQLEquals('u1.id as id, c1.discr as discr', $selectClause);
}
}

0 comments on commit 39098ce

Please sign in to comment.