- Work done on insert() and update() function from QueryBuilder.
- Fixed save() and saveAll() from repository - QueryBuilder can now be flushed after queries.
This commit is contained in:
1 parent
79fdabe786
commit
d1961ec807
9 files changed
+122
-44
No files matched your search
+17
-10
@@ -31,9 +31,14 @@ class Repository
|
||||
return $this->limit(1)->collectionFromQuery()[0] ?? null;
|
||||
}
|
||||
|
||||
public function loadOneFromField($field, $value) : ? object
|
||||
{
|
||||
return $this->where($field, $value)->loadOne();
|
||||
}
|
||||
|
||||
public function loadFromPk($value, $primaryKey = "id") : ? object
|
||||
{
|
||||
return $this->where($primaryKey, $value)->loadOne();
|
||||
return $this->loadOneFromField($primaryKey, $value);
|
||||
}
|
||||
|
||||
public function loadAll() : EntityCollection
|
||||
@@ -99,24 +104,24 @@ class Repository
|
||||
if ( $primaryKeyDefinition === null ) {
|
||||
throw new \Exception(sprintf("No primary key found for entity %s", $this->entityClass));
|
||||
}
|
||||
|
||||
$pkField = key($primaryKeyDefinition);
|
||||
$pkFieldName = $primaryKeyDefinition[$pkField]->name ?? $pkField;
|
||||
$this->where($pkFieldName, $dataset[$pkFieldName]);
|
||||
|
||||
|
||||
$diff = array_diff_assoc($dataset, $entity->entityGetDataset(true));
|
||||
|
||||
if ( [] !== $diff ) {
|
||||
$pkField = key($primaryKeyDefinition);
|
||||
$pkFieldName = $primaryKeyDefinition[$pkField]->name ?? $pkField;
|
||||
$this->where($pkFieldName, $dataset[$pkFieldName]);
|
||||
|
||||
$update = $this->updateSqlQuery($diff)->runQuery();
|
||||
|
||||
return (bool) $update->rowCount();
|
||||
}
|
||||
return $update ? (bool) $update->rowCount() : false;
|
||||
}
|
||||
}
|
||||
|
||||
return false;
|
||||
}
|
||||
|
||||
public function saveAll(EntityCollection $collection) : bool
|
||||
public function saveAll(EntityCollection $collection) : void
|
||||
{
|
||||
foreach($collection as $entity) {
|
||||
$this->save($entity);
|
||||
@@ -179,6 +184,8 @@ class Repository
|
||||
|
||||
public function join(string $type, $table, $field, $value) : self
|
||||
{
|
||||
$this->queryBuilder->join($type, $table, $field, $value);
|
||||
|
||||
return $this;
|
||||
}
|
||||
|
||||
@@ -370,7 +377,7 @@ class Repository
|
||||
return $entityCollection;
|
||||
}
|
||||
|
||||
public function runQuery() : \PDOStatement
|
||||
public function runQuery() : ? \PDOStatement
|
||||
{
|
||||
$this->finalizeQuery();
|
||||
|
||||
|
||||
Reference in new issue
Block a user