-
Notifications
You must be signed in to change notification settings - Fork 2.5k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #7079 from mairo744/hotfix/sqlite-join-table-name
fix getJoinTableName for sqlite with schema attribute
- Loading branch information
Showing
2 changed files
with
125 additions
and
1 deletion.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
123 changes: 123 additions & 0 deletions
123
tests/Doctrine/Tests/ORM/Functional/Ticket/GH7079Test.php
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,123 @@ | ||
<?php | ||
|
||
declare(strict_types=1); | ||
|
||
namespace Doctrine\Tests\ORM\Functional\Ticket; | ||
|
||
use Doctrine\Common\Persistence\Mapping\RuntimeReflectionService; | ||
use Doctrine\DBAL\Platforms\AbstractPlatform; | ||
use Doctrine\ORM\Mapping\ClassMetadata; | ||
use Doctrine\ORM\Mapping\DefaultQuoteStrategy; | ||
use Doctrine\Tests\OrmFunctionalTestCase; | ||
|
||
/** | ||
* @group GH7079 | ||
*/ | ||
final class GH7079Test extends OrmFunctionalTestCase | ||
{ | ||
/** @var DefaultQuoteStrategy */ | ||
private $strategy; | ||
|
||
/** @var AbstractPlatform */ | ||
private $platform; | ||
|
||
/** | ||
* {@inheritDoc} | ||
*/ | ||
protected function setUp() : void | ||
{ | ||
parent::setUp(); | ||
|
||
$this->platform = $this->_em->getConnection()->getDatabasePlatform(); | ||
$this->strategy = new DefaultQuoteStrategy(); | ||
} | ||
|
||
public function testGetTableName() : void | ||
{ | ||
$table = [ | ||
'name' => 'cms_user', | ||
'schema' => 'cms', | ||
]; | ||
|
||
$cm = $this->createClassMetadata(GH7079CmsUser::class); | ||
$cm->setPrimaryTable($table); | ||
|
||
self::assertEquals($this->getTableFullName($table), $this->strategy->getTableName($cm, $this->platform)); | ||
} | ||
|
||
public function testJoinTableName() : void | ||
{ | ||
$table = [ | ||
'name' => 'cmsaddress_cmsuser', | ||
'schema' => 'cms', | ||
]; | ||
|
||
$cm = $this->createClassMetadata(GH7079CmsAddress::class); | ||
$cm->mapManyToMany( | ||
[ | ||
'fieldName' => 'user', | ||
'targetEntity' => 'DDC7079CmsUser', | ||
'inversedBy' => 'users', | ||
'joinTable' => $table, | ||
] | ||
); | ||
|
||
self::assertEquals( | ||
$this->getTableFullName($table), | ||
$this->strategy->getJoinTableName($cm->associationMappings['user'], $cm, $this->platform) | ||
); | ||
} | ||
|
||
private function getTableFullName(array $table) : string | ||
{ | ||
$join = '.'; | ||
if (! $this->platform->supportsSchemas() && $this->platform->canEmulateSchemas()) { | ||
$join = '__'; | ||
} | ||
|
||
return $table['schema'] . $join . $table['name']; | ||
} | ||
|
||
private function createClassMetadata(string $className) : ClassMetadata | ||
{ | ||
$cm = new ClassMetadata($className); | ||
$cm->initializeReflection(new RuntimeReflectionService()); | ||
|
||
return $cm; | ||
} | ||
} | ||
|
||
/** | ||
* @Entity | ||
* @Table(name="cms_users", schema="cms") | ||
*/ | ||
class GH7079CmsUser | ||
{ | ||
/** | ||
* @Id @Column(type="integer") | ||
* @GeneratedValue | ||
*/ | ||
public $id; | ||
|
||
/** @OneToOne(targetEntity=GH7079CmsAddress::class, mappedBy="user", cascade={"persist"}, orphanRemoval=true) */ | ||
public $address; | ||
} | ||
|
||
/** | ||
* @Entity | ||
* @Table(name="cms_addresses", schema="cms") | ||
*/ | ||
class GH7079CmsAddress | ||
{ | ||
/** | ||
* @Column(type="integer") | ||
* @Id @GeneratedValue | ||
*/ | ||
public $id; | ||
|
||
/** | ||
* @OneToOne(targetEntity=GH7079CmsUser::class, inversedBy="address") | ||
* @JoinColumn(referencedColumnName="id") | ||
*/ | ||
public $user; | ||
} |