Skip to content

Commit

Permalink
Fix to Eloquent Destination to ensure casting functions as expected w…
Browse files Browse the repository at this point in the history
…hen rows are updated
  • Loading branch information
DivineOmega committed Mar 27, 2019
1 parent 92ef459 commit b46f62a
Show file tree
Hide file tree
Showing 2 changed files with 9 additions and 4 deletions.
8 changes: 6 additions & 2 deletions src/Objects/Destinations/EloquentDestination.php
Original file line number Diff line number Diff line change
Expand Up @@ -46,11 +46,15 @@ private function updateDataRow(DataRow $dataRow)
{
$keyDataItems = $dataRow->getKeyDataItems();

$record = $this->model->where(function ($query) use ($keyDataItems) {
$records = $this->model->where(function ($query) use ($keyDataItems) {
foreach ($keyDataItems as $keyDataItem) {
$query->where($keyDataItem->fieldName, $keyDataItem->value);
}
})->update($this->getAssocArrayFromDataRow($dataRow));
})->get();

foreach($records as $record) {
$record->update($this->getAssocArrayFromDataRow($dataRow));
}
}

public function putDataRows(array $dataRows)
Expand Down
5 changes: 3 additions & 2 deletions tests/Unit/EloquentDestinationTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,8 @@ private function getDestination()
$stmt = $this->pdo->prepare($sql);
$stmt->execute();

$sql = 'CREATE TABLE IF NOT EXISTS users (name TEXT, value INTEGER)';

$sql = 'CREATE TABLE IF NOT EXISTS users (id integer primary key autoincrement, name TEXT, value INTEGER)';
$stmt = $this->pdo->prepare($sql);
$stmt->execute();

Expand Down Expand Up @@ -60,7 +61,7 @@ private function alterDataRows(array $dataRows)

private function getActualArray()
{
$sql = 'SELECT * FROM users';
$sql = 'SELECT name, value FROM users';
$stmt = $this->pdo->prepare($sql);
$stmt->execute();

Expand Down

0 comments on commit b46f62a

Please sign in to comment.