Skip to content

Commit

Permalink
no need to reset id field type to string, guessing fixed in data
Browse files Browse the repository at this point in the history
  • Loading branch information
mvorisek committed Nov 12, 2021
1 parent 4702d2d commit fcdee8f
Showing 1 changed file with 2 additions and 3 deletions.
5 changes: 2 additions & 3 deletions src/View.php
Original file line number Diff line number Diff line change
Expand Up @@ -178,19 +178,18 @@ public function setSource(array $data, $fields = null)
{
// ID with zero value is not supported (at least in MySQL replaces it with next AI value)
if (isset($data[0])) {
if ($data === array_values($data)) {
if (array_is_list($data)) {
$oldData = $data;
$data = [];
foreach ($oldData as $k => $row) {
$data[$k + 1000 * 1000 * 1000] = $row; // large offset to prevent accessing wrong data by old key
$data[$k + 1_000_000_000] = $row; // large offset to prevent accessing wrong data by old key
}
} else {
throw new Exception('Source data contains unsupported zero key');
}
}

$this->setModel(new Model(new Static_($data)), $fields); // @phpstan-ignore-line
$this->model->getField($this->model->id_field)->type = null; // TODO probably unwanted

return $this->model;
}
Expand Down

0 comments on commit fcdee8f

Please sign in to comment.