Skip to content

Commit

Permalink
mapper: added delimiting table names in SQL joins [closes #228]
Browse files Browse the repository at this point in the history
  • Loading branch information
hrach committed Aug 27, 2017
1 parent ed90dce commit 565558b
Show file tree
Hide file tree
Showing 2 changed files with 6 additions and 6 deletions.
4 changes: 2 additions & 2 deletions src/Mapper/Dbal/QueryBuilderHelper.php
Expand Up @@ -128,7 +128,7 @@ private function normalizeAndAddJoins(array $levels, $sourceEntity, QueryBuilder

$builder->leftJoin(
$sourceAlias,
$joinTable,
"[$joinTable]",
self::getAlias($joinTable),
"[$sourceAlias.$sourceColumn] = [$joinTable.$inColumn]"
);
Expand All @@ -148,7 +148,7 @@ private function normalizeAndAddJoins(array $levels, $sourceEntity, QueryBuilder

$builder->leftJoin(
$sourceAlias,
$targetTable,
"[$targetTable]",
$targetAlias,
"[$sourceAlias.$sourceColumn] = [$targetAlias.$targetColumn]"
);
Expand Down
8 changes: 4 additions & 4 deletions tests/cases/unit/Mapper/Dbal/QueryBuilderHelperTest.phpt
Expand Up @@ -100,7 +100,7 @@ class QueryBuilderHelperTest extends TestCase
$this->entityMetadata->shouldReceive('getProperty')->once()->with('name')->andReturn(new PropertyMetadata());
$this->reflection->shouldReceive('convertEntityToStorage')->once()->with(['name' => NULL])->andReturn(['name' => NULL]);

$this->queryBuilder->shouldReceive('leftJoin')->once()->with('books', 'authors', 'translator', '[books.translator_id] = [translator.id]');
$this->queryBuilder->shouldReceive('leftJoin')->once()->with('books', '[authors]', 'translator', '[books.translator_id] = [translator.id]');
$this->queryBuilder->shouldReceive('addOrderBy')->once()->with('[translator.name]');

$this->builderHelper->processOrderByExpression('this->translator->name', ICollection::ASC, $this->queryBuilder);
Expand Down Expand Up @@ -155,9 +155,9 @@ class QueryBuilderHelperTest extends TestCase
$this->reflection->shouldReceive('convertEntityToStorage')->once()->with(['name' => ['tag_name']])->andReturn(['name' => ['tag_name']]);


$this->queryBuilder->shouldReceive('leftJoin')->once()->with('authors', 'books', 'translatedBooks', '[authors.id] = [translatedBooks.translator_id]');
$this->queryBuilder->shouldReceive('leftJoin')->once()->with('translatedBooks', 'books_x_tags', 'books_x_tags', '[translatedBooks.id] = [books_x_tags.book_id]');
$this->queryBuilder->shouldReceive('leftJoin')->once()->with('books_x_tags', 'tags', 'tags_', '[books_x_tags.tag_id] = [tags_.id]');
$this->queryBuilder->shouldReceive('leftJoin')->once()->with('authors', '[books]', 'translatedBooks', '[authors.id] = [translatedBooks.translator_id]');
$this->queryBuilder->shouldReceive('leftJoin')->once()->with('translatedBooks', '[books_x_tags]', 'books_x_tags', '[translatedBooks.id] = [books_x_tags.book_id]');
$this->queryBuilder->shouldReceive('leftJoin')->once()->with('books_x_tags', '[tags]', 'tags_', '[books_x_tags.tag_id] = [tags_.id]');
$this->queryBuilder->shouldReceive('andWhere')->once()->with('[tags_.name] IN %any', ['tag_name']);

$this->builderHelper->processWhereExpression('this->translatedBooks->tags->name', ['tag_name'], $this->queryBuilder, $needDistinct);
Expand Down

0 comments on commit 565558b

Please sign in to comment.