- Some bugfixes were made, added a new diff before saving results. Also, a new method was added for insert, update and delete respectively for other drivers to override as needed
This commit is contained in:
1 parent
58afe841e7
commit
dc5e088551
7 files changed
+111
-29
No files matched your search
+13
-10
@@ -62,19 +62,19 @@ trait EntityTrait {
|
||||
/**
|
||||
* @Ignore
|
||||
*/
|
||||
public function entityFillFromDataset(iterable $dataset) : self
|
||||
public function entityFillFromDataset(iterable $dataset, bool $overwriteDataset = false) : self
|
||||
{
|
||||
$loaded = $this->isLoaded();
|
||||
|
||||
|
||||
$entityResolver = $this->resolveEntity();
|
||||
|
||||
|
||||
foreach($dataset as $key => $value) {
|
||||
$field = $entityResolver->field(strtolower($key), EntityResolver::KEY_COLUMN_NAME, false) ?? null;
|
||||
|
||||
|
||||
if ( $field === null ) {
|
||||
$field = $entityResolver->field(strtolower($key), EntityResolver::KEY_LC_ENTITY_NAME, false);
|
||||
}
|
||||
|
||||
|
||||
if ( $field === null ) {
|
||||
if ($this->entityStrictFieldsDeclaration ) {
|
||||
throw new \Exception("Field `$key` can not be found within your entity ".static::class);
|
||||
@@ -98,9 +98,9 @@ trait EntityTrait {
|
||||
|
||||
if ( $field['type'] === 'string' ) {
|
||||
$annotation = $entityResolver->searchFieldAnnotation($field['name'], new Field() );
|
||||
|
||||
|
||||
if ( $annotation->length ?? null ) {
|
||||
$value = substr($value, 0, $annotation->length);
|
||||
$value = mb_substr($value, 0, $annotation->length);
|
||||
}
|
||||
}
|
||||
elseif ( $field['type'] === 'bool' ) {
|
||||
@@ -112,17 +112,20 @@ trait EntityTrait {
|
||||
elseif ( ! $field['builtin'] ) {
|
||||
$this->{$field['name']} = Ulmus::instanciateObject($field['type'], [ $value ]);
|
||||
}
|
||||
|
||||
|
||||
# Keeping original data to diff on UPDATE query
|
||||
if ( ! $loaded || $isLoadedDataset ) {
|
||||
if ( ! $loaded ) {
|
||||
#if ( $field !== null ) {
|
||||
# $annotation = $entityResolver->searchFieldAnnotation($field['name'], new Field() );
|
||||
# $this->entityLoadedDataset[$annotation ? $annotation->name : $field['name']] = $dataset; # <--------- THIS TO FIX !!!!!!
|
||||
#}
|
||||
$this->entityLoadedDataset = array_change_key_case($dataset, \CASE_LOWER);
|
||||
}
|
||||
elseif ($overwriteDataset) {
|
||||
$this->entityLoadedDataset = array_change_key_case($dataset, \CASE_LOWER) + $this->entityLoadedDataset;
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
return $this;
|
||||
}
|
||||
|
||||
|
||||
Reference in new issue
Block a user