From 36162c6486c052891672dc08e392a28322c46bd5 Mon Sep 17 00:00:00 2001 From: Dave M Date: Mon, 5 Jan 2026 12:37:55 +0000 Subject: [PATCH] -Empty dataset can not be saved --- src/Query/Values.php | 6 +++++- src/Repository.php | 4 ++++ 2 files changed, 9 insertions(+), 1 deletion(-) diff --git a/src/Query/Values.php b/src/Query/Values.php index 44712b5..78299f7 100644 --- a/src/Query/Values.php +++ b/src/Query/Values.php @@ -10,7 +10,7 @@ class Values extends Fragment { public ? int $fieldCount = null; - public array $rows; + public array $rows = []; public QueryBuilderInterface $queryBuilder; @@ -21,6 +21,10 @@ class Values extends Fragment { public function add(array $row) : self { + if ($row === []) { + return $this; + } + if ($this->fieldCount === null) { $this->fieldCount = count($row); } diff --git a/src/Repository.php b/src/Repository.php index bbc446f..e0d1064 100644 --- a/src/Repository.php +++ b/src/Repository.php @@ -199,6 +199,10 @@ class Repository implements RepositoryInterface if ( $replace || ! $entity->isLoaded() ) { # $dataset = array_filter($dataset, fn($item, $field) => ! ($this->entityResolver->searchFieldAnnotation($field, new Field, false)->readonly ?? false), \ARRAY_FILTER_USE_BOTH); + if (empty($dataset)) { + throw new \InvalidArgumentException("Unable to add a new row from an empty dataset."); + } + $pdoObject = $this->insertSqlQuery($fieldsAndValue ?? $dataset, $replace)->runInsertQuery(); if ( null !== $primaryKeyDefinition ) {