Skip to content
This repository was archived by the owner on Jan 29, 2020. It is now read-only.

Join update fix #301

Merged
merged 4 commits into from
Apr 3, 2018
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
13 changes: 12 additions & 1 deletion src/Sql/Update.php
Original file line number Diff line number Diff line change
Expand Up @@ -187,7 +187,18 @@ protected function processSet(
) {
$setSql = [];
foreach ($this->set as $column => $value) {
$prefix = $platform->quoteIdentifier($column) . ' = ';
$prefix = $this->resolveColumnValue(
[
'column' => $column,
'fromTable' => '',
'isIdentifier' => true,
],
$platform,
$driver,
$parameterContainer,
'column'
);
$prefix .= ' = ';
if (is_scalar($value) && $parameterContainer) {
$setSql[] = $prefix . $driver->formatParameterName($column);
$parameterContainer->offsetSet($column, $value);
Expand Down
26 changes: 26 additions & 0 deletions test/Sql/UpdateTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -391,6 +391,32 @@ public function testJoin()
);
}

/**
* Here test if we want update fields from specific table.
* Important when we're updating fields that are existing in several tables in one query.
* The same test as above but here we will specify table in update params
*/
public function testJoinMultiUpdate()
{
$this->update->table('Document');
$this->update->set(['Documents.x' => 'y'])
->join(
'User',
'User.UserId = Document.UserId'
)
->join(
'Category',
'Category.CategoryId = Document.CategoryId',
Join::JOIN_LEFT
);

self::assertEquals(
'UPDATE "Document" INNER JOIN "User" ON "User"."UserId" = "Document"."UserId" '
. 'LEFT JOIN "Category" ON "Category"."CategoryId" = "Document"."CategoryId" SET "Documents"."x" = \'y\'',
$this->update->getSqlString(new TrustingSql92Platform())
);
}

/**
* @testdox unit test: Test join() returns Update object (is chainable)
* @covers \Zend\Db\Sql\Update::join
Expand Down