4 Commits
2.4.0 ... 2.4.2

Author SHA1 Message Date
b19654bc70 Merge branch 'develop' into release 2022-10-10 17:32:48 -03:00
fe67519682 Added column = property handling for mapping 2022-10-10 17:32:34 -03:00
0af6be2c8e Merge branch 'develop' into release 2022-10-10 16:46:57 -03:00
0a9bed1735 Fixes 2022-10-10 16:46:44 -03:00
3 changed files with 12 additions and 3 deletions

View File

@ -78,7 +78,7 @@ abstract class Model implements ModelInterface
if ($method->getName() === 'getRepository') {
continue;
}
$p = strtolower(str_replace('get', '', $method->getName()));
$p = strtolower(preg_replace('/(?<!^)[A-Z]/', '_$0', str_replace('get', '', $method->getName())));
if (!isset($this->{$p})) {
continue;
}

View File

@ -109,6 +109,9 @@ abstract class Repository implements RepositoryInterface
return $mapping->column;
}
}
if (in_array($property, $this->getColumns())) {
return $property;
}
throw new \InvalidArgumentException("Property {$property} not found in mapping in " . get_called_class());
}
public function findPropertyByColumn(string $column): string
@ -118,6 +121,9 @@ abstract class Repository implements RepositoryInterface
return $mapping->property;
}
}
if (in_array($column, $this->getProperties())) {
return $column;
}
throw new \InvalidArgumentException("Column {$column} not found in mapping in " . get_called_class());
}
@ -251,6 +257,9 @@ abstract class Repository implements RepositoryInterface
} catch (\InvalidArgumentException $e) {
continue;
}
if (isset($data[$column])) {
continue;
}
$m = $this->getMethod($property);
if (!method_exists($model, $m)) {
continue;
@ -277,7 +286,7 @@ abstract class Repository implements RepositoryInterface
$values = $this->mapArray($model, []);
$cols = array_fill(0, count($values), '?');
$query = $this->getQueryBuilder()->insert($this->getTable())->columns($this->getColumns())->values($cols);
$this->getConnection()->execute($query, $values);
$this->getConnection()->execute($query, array_values($values));
}
public function update(Model $model): void
{

View File

@ -215,7 +215,7 @@ interface Repository
public function fillData(Model $model, array $data): Model;
/**
* Fill data array with Model values
* Fill data array with Model values. Accepts a preset data array
* @param Model $model
* @param array $data
* @return array