[2.0] DDC-341 - Added Composite Model-Set and 3 tests, fixed two bugs in SqlWalker with Composite Key support
This commit is contained in:
parent
848142d1d8
commit
95994f7a44
@ -732,14 +732,19 @@ class SqlWalker implements TreeWalker
|
||||
$joinTableAlias = $this->getSqlTableAlias($joinTable['name'], $joinedDqlAlias);
|
||||
$sql .= $assoc->getQuotedJoinTableName($this->_platform) . ' ' . $joinTableAlias . ' ON ';
|
||||
|
||||
$first = true;
|
||||
if ($relation->isOwningSide) {
|
||||
foreach ($assoc->relationToSourceKeyColumns as $relationColumn => $sourceColumn) {
|
||||
if ( ! $first) $sql .= ' AND '; else $first = false;
|
||||
|
||||
$sql .= $sourceTableAlias . '.' . $sourceClass->getQuotedColumnName($sourceClass->fieldNames[$sourceColumn], $this->_platform)
|
||||
. ' = '
|
||||
. $joinTableAlias . '.' . $relationColumn;
|
||||
}
|
||||
} else {
|
||||
foreach ($assoc->relationToTargetKeyColumns as $relationColumn => $targetColumn) {
|
||||
if ( ! $first) $sql .= ' AND '; else $first = false;
|
||||
|
||||
$sql .= $sourceTableAlias . '.' . $targetClass->getQuotedColumnName($targetClass->fieldNames[$targetColumn], $this->_platform)
|
||||
. ' = '
|
||||
. $joinTableAlias . '.' . $relationColumn;
|
||||
@ -751,14 +756,19 @@ class SqlWalker implements TreeWalker
|
||||
? ' LEFT JOIN ' : ' INNER JOIN ';
|
||||
$sql .= $targetTableName . ' ' . $targetTableAlias . ' ON ';
|
||||
|
||||
$first = true;
|
||||
if ($relation->isOwningSide) {
|
||||
foreach ($assoc->relationToTargetKeyColumns as $relationColumn => $targetColumn) {
|
||||
if ( ! $first) $sql .= ' AND '; else $first = false;
|
||||
|
||||
$sql .= $targetTableAlias . '.' . $targetClass->getQuotedColumnName($targetClass->fieldNames[$targetColumn], $this->_platform)
|
||||
. ' = '
|
||||
. $joinTableAlias . '.' . $relationColumn;
|
||||
}
|
||||
} else {
|
||||
foreach ($assoc->relationToSourceKeyColumns as $relationColumn => $sourceColumn) {
|
||||
if ( ! $first) $sql .= ' AND '; else $first = false;
|
||||
|
||||
$sql .= $targetTableAlias . '.' . $sourceClass->getQuotedColumnName($sourceClass->fieldNames[$sourceColumn], $this->_platform)
|
||||
. ' = '
|
||||
. $joinTableAlias . '.' . $relationColumn;
|
||||
|
39
tests/Doctrine/Tests/Models/Navigation/NavCountry.php
Normal file
39
tests/Doctrine/Tests/Models/Navigation/NavCountry.php
Normal file
@ -0,0 +1,39 @@
|
||||
<?php
|
||||
|
||||
namespace Doctrine\Tests\Models\Navigation;
|
||||
|
||||
/**
|
||||
* @Entity
|
||||
* @Table(name="navigation_countries")
|
||||
*/
|
||||
class NavCountry
|
||||
{
|
||||
/**
|
||||
* @Id
|
||||
* @Column(type="integer")
|
||||
* @generatedValue
|
||||
*/
|
||||
private $id;
|
||||
|
||||
/**
|
||||
* @Column(type="string")
|
||||
*/
|
||||
private $name;
|
||||
|
||||
/**
|
||||
* @OneToMany(targetEntity="NavPointOfInterest", mappedBy="country")
|
||||
*/
|
||||
private $pois;
|
||||
|
||||
function __construct($name) {
|
||||
$this->name = $name;
|
||||
}
|
||||
|
||||
public function getId() {
|
||||
return $this->id;
|
||||
}
|
||||
|
||||
public function getName() {
|
||||
return $this->name;
|
||||
}
|
||||
}
|
48
tests/Doctrine/Tests/Models/Navigation/NavPhotos.php
Normal file
48
tests/Doctrine/Tests/Models/Navigation/NavPhotos.php
Normal file
@ -0,0 +1,48 @@
|
||||
<?php
|
||||
|
||||
namespace Doctrine\Tests\Models\Navigation;
|
||||
|
||||
/**
|
||||
* @Entity
|
||||
* @Table(name="navigation_photos")
|
||||
*/
|
||||
class NavPhotos
|
||||
{
|
||||
/**
|
||||
* @Id
|
||||
* @column(type="integer")
|
||||
* @generatedValue
|
||||
*/
|
||||
private $id;
|
||||
|
||||
/**
|
||||
* @ManyToOne(targetEntity="NavPointOfInterest")
|
||||
* @JoinColumns({
|
||||
* @JoinColumn(name="poi_long", referencedColumnName="nav_long"),
|
||||
* @JoinColumn(name="poi_lat", referencedColumnName="nav_lat")
|
||||
* })
|
||||
*/
|
||||
private $poi;
|
||||
|
||||
/**
|
||||
* @column(type="string")
|
||||
*/
|
||||
private $file;
|
||||
|
||||
function __construct($poi, $file) {
|
||||
$this->poi = $poi;
|
||||
$this->file = $file;
|
||||
}
|
||||
|
||||
public function getId() {
|
||||
return $this->id;
|
||||
}
|
||||
|
||||
public function getPointOfInterest() {
|
||||
return $this->poi;
|
||||
}
|
||||
|
||||
public function getFile() {
|
||||
return $this->file;
|
||||
}
|
||||
}
|
@ -0,0 +1,56 @@
|
||||
<?php
|
||||
|
||||
namespace Doctrine\Tests\Models\Navigation;
|
||||
|
||||
/**
|
||||
* @Entity
|
||||
* @Table(name="navigation_pois")
|
||||
*/
|
||||
class NavPointOfInterest
|
||||
{
|
||||
/**
|
||||
* @Id
|
||||
* @Column(type="integer", name="nav_long")
|
||||
*/
|
||||
private $long;
|
||||
|
||||
/**
|
||||
* @Id
|
||||
* @Column(type="integer", name="nav_lat")
|
||||
*/
|
||||
private $lat;
|
||||
|
||||
/**
|
||||
* @Column(type="string")
|
||||
*/
|
||||
private $name;
|
||||
|
||||
/**
|
||||
* @ManyToOne(targetEntity="NavCountry")
|
||||
*/
|
||||
private $country;
|
||||
|
||||
public function __construct($lat, $long, $name, $country)
|
||||
{
|
||||
$this->lat = $lat;
|
||||
$this->long = $long;
|
||||
$this->name = $name;
|
||||
$this->country = $country;
|
||||
}
|
||||
|
||||
public function getLong() {
|
||||
return $this->long;
|
||||
}
|
||||
|
||||
public function getLat() {
|
||||
return $this->lat;
|
||||
}
|
||||
|
||||
public function getName() {
|
||||
return $this->name;
|
||||
}
|
||||
|
||||
public function getCountry() {
|
||||
return $this->country;
|
||||
}
|
||||
}
|
61
tests/Doctrine/Tests/Models/Navigation/NavTour.php
Normal file
61
tests/Doctrine/Tests/Models/Navigation/NavTour.php
Normal file
@ -0,0 +1,61 @@
|
||||
<?php
|
||||
|
||||
namespace Doctrine\Tests\Models\Navigation;
|
||||
|
||||
/**
|
||||
* @Entity
|
||||
* @Table(name="navigation_tours")
|
||||
*/
|
||||
class NavTour
|
||||
{
|
||||
/**
|
||||
* @Id
|
||||
* @Column(type="integer")
|
||||
* @generatedValue
|
||||
*/
|
||||
private $id;
|
||||
|
||||
/**
|
||||
* @column(type="string")
|
||||
*/
|
||||
private $name;
|
||||
|
||||
/**
|
||||
* @ManyToMany(targetEntity="NavPointOfInterest")
|
||||
* @JoinTable(name="navigation_tour_pois",
|
||||
* joinColumns={@JoinColumn(name="tour_id", referencedColumnName="id")},
|
||||
* inverseJoinColumns={
|
||||
* @JoinColumn(name="poi_long", referencedColumnName="nav_long"),
|
||||
* @JoinColumn(name="poi_lat", referencedColumnName="nav_lat")
|
||||
* }
|
||||
* )
|
||||
*
|
||||
*/
|
||||
private $pois;
|
||||
|
||||
public function __construct($name)
|
||||
{
|
||||
$this->name = $name;
|
||||
$this->pois = new \Doctrine\Common\Collections\ArrayCollection;
|
||||
}
|
||||
|
||||
public function addPointOfInterest(NavPointOfInterest $poi)
|
||||
{
|
||||
$this->pois[] = $poi;
|
||||
}
|
||||
|
||||
public function getPointOfInterests()
|
||||
{
|
||||
return $this->pois;
|
||||
}
|
||||
|
||||
public function getName()
|
||||
{
|
||||
return $this->name;
|
||||
}
|
||||
|
||||
public function getId()
|
||||
{
|
||||
return $this->id;
|
||||
}
|
||||
}
|
@ -45,6 +45,7 @@ class AllTests
|
||||
$suite->addTestSuite('Doctrine\Tests\ORM\Functional\ManyToManySelfReferentialAssociationTest');
|
||||
$suite->addTestSuite('Doctrine\Tests\ORM\Functional\OrderedCollectionTest');
|
||||
$suite->addTestSuite('Doctrine\Tests\ORM\Functional\OrderedJoinedTableInheritanceCollectionTest');
|
||||
$suite->addTestSuite('Doctrine\Tests\ORM\Functional\CompositePrimaryKeyTest');
|
||||
$suite->addTestSuite('Doctrine\Tests\ORM\Functional\ReferenceProxyTest');
|
||||
$suite->addTestSuite('Doctrine\Tests\ORM\Functional\LifecycleCallbackTest');
|
||||
$suite->addTestSuite('Doctrine\Tests\ORM\Functional\StandardEntityPersisterTest');
|
||||
|
@ -0,0 +1,95 @@
|
||||
<?php
|
||||
|
||||
namespace Doctrine\Tests\ORM\Functional;
|
||||
use Doctrine\Tests\Models\Navigation\NavCountry;
|
||||
use Doctrine\Tests\Models\Navigation\NavPointOfInterest;
|
||||
use Doctrine\Tests\Models\Navigation\NavTour;
|
||||
|
||||
require_once __DIR__ . '/../../TestInit.php';
|
||||
|
||||
class CompositePrimaryKeyTest extends \Doctrine\Tests\OrmFunctionalTestCase
|
||||
{
|
||||
public function setUp()
|
||||
{
|
||||
$this->useModelSet('navigation');
|
||||
parent::setUp();
|
||||
}
|
||||
|
||||
public function putGermanysBrandenburderTor()
|
||||
{
|
||||
$country = new NavCountry("Germany");
|
||||
$this->_em->persist($country);
|
||||
$poi = new NavPointOfInterest(100, 200, "Brandenburger Tor", $country);
|
||||
$this->_em->persist($poi);
|
||||
$this->_em->flush();
|
||||
$this->_em->clear();
|
||||
}
|
||||
|
||||
public function putTripAroundEurope()
|
||||
{
|
||||
$poi = $this->_em->find('Doctrine\Tests\Models\Navigation\NavPointOfInterest', array('lat' => 100, 'long' => 200));
|
||||
|
||||
$tour = new NavTour("Trip around Europe");
|
||||
$tour->addPointOfInterest($poi);
|
||||
|
||||
$this->_em->persist($tour);
|
||||
$this->_em->flush();
|
||||
$this->_em->clear();
|
||||
|
||||
return $tour;
|
||||
}
|
||||
|
||||
public function testPersistCompositePkEntity()
|
||||
{
|
||||
$this->putGermanysBrandenburderTor();
|
||||
|
||||
$poi = $this->_em->find('Doctrine\Tests\Models\Navigation\NavPointOfInterest', array('lat' => 100, 'long' => 200));
|
||||
|
||||
$this->assertType('Doctrine\Tests\Models\Navigation\NavPointOfInterest', $poi);
|
||||
$this->assertEquals(100, $poi->getLat());
|
||||
$this->assertEquals(200, $poi->getLong());
|
||||
$this->assertEquals('Brandenburger Tor', $poi->getName());
|
||||
}
|
||||
|
||||
public function testManyToManyCompositeRelation()
|
||||
{
|
||||
$this->putGermanysBrandenburderTor();
|
||||
$tour = $this->putTripAroundEurope();
|
||||
|
||||
$tour = $this->_em->find('Doctrine\Tests\Models\Navigation\NavTour', $tour->getId());
|
||||
|
||||
$this->assertEquals(1, count($tour->getPointOfInterests()));
|
||||
}
|
||||
|
||||
public function testCompositeDqlEagerFetching()
|
||||
{
|
||||
$this->putGermanysBrandenburderTor();
|
||||
$this->putTripAroundEurope();
|
||||
|
||||
$dql = 'SELECT t, p, c FROM Doctrine\Tests\Models\Navigation\NavTour t ' .
|
||||
'INNER JOIN t.pois p INNER JOIN p.country c';
|
||||
$tours = $this->_em->createQuery($dql)->getResult();
|
||||
|
||||
$this->assertEquals(1, count($tours));
|
||||
|
||||
$pois = $tours[0]->getPointOfInterests();
|
||||
|
||||
$this->assertEquals(1, count($pois));
|
||||
$this->assertEquals('Brandenburger Tor', $pois[0]->getName());
|
||||
}
|
||||
|
||||
public function testCompositeCollectionMemberExpression()
|
||||
{
|
||||
$this->markTestSkipped('How to test this?');
|
||||
|
||||
$this->putGermanysBrandenburderTor();
|
||||
$this->putTripAroundEurope();
|
||||
|
||||
$dql = 'SELECT t FROM Doctrine\Tests\Models\Navigation\NavTour t, Doctrine\Tests\Models\Navigation\NavPointOfInterest p ' .
|
||||
'WHERE p MEMBER OF t.pois';
|
||||
$tours = $this->_em->createQuery($dql)
|
||||
->getResult();
|
||||
|
||||
$this->assertEquals(1, count($tours));
|
||||
}
|
||||
}
|
Loading…
Reference in New Issue
Block a user