-
Notifications
You must be signed in to change notification settings - Fork 12
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Crate (like Postgres and Sqlite) does not allow table prefix in updates.
We remove table prefix that was added in laravel/framework#26031
- Loading branch information
Ratko Rudic
committed
Mar 5, 2019
1 parent
11ae628
commit e7026b5
Showing
1 changed file
with
45 additions
and
0 deletions.
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,45 @@ | ||
<?php | ||
|
||
namespace RatkoR\Crate\Eloquent; | ||
|
||
use Illuminate\Database\Eloquent\Builder as BaseBuilder; | ||
|
||
class Builder extends BaseBuilder | ||
{ | ||
/** | ||
* Add the "updated at" column to an array of values. | ||
* | ||
* Note: Crate (like postgres and sqlite) MUST not have table prefix in | ||
* update query. It throws with: | ||
* [SQLParseException: Column reference "my_table.update_at" | ||
* has too many parts. A column must not have a schema or a table here.] | ||
* | ||
* Remove table prefix for updated_at field. | ||
* Eq: | ||
* update t1 set a = 1, t1.updated_at = 123456 | ||
* change to: | ||
* update t1 set a = 1, updated_at = 123456 | ||
* | ||
* See also: https://github.com/laravel/framework/pull/26031 | ||
* | ||
* @param array $values | ||
* @return array | ||
*/ | ||
protected function addUpdatedAtColumn(array $values) | ||
{ | ||
$values = parent::addUpdatedAtColumn($values); | ||
$newValues = []; | ||
|
||
$updatedAtColumn = $this->model->getUpdatedAtColumn(); | ||
|
||
foreach ($values as $field => $value) { | ||
$isUpdateAtField = (strpos($field, '.' . $updatedAtColumn) !== false); | ||
|
||
$isUpdateAtField ? | ||
$newValues[$updatedAtColumn] = $value : | ||
$newValues[$field] = $value; | ||
} | ||
|
||
return $newValues; | ||
} | ||
} |