Compare commits
4 Commits
Author | SHA1 | Date | |
---|---|---|---|
b19654bc70 | |||
fe67519682 | |||
0af6be2c8e | |||
0a9bed1735 |
@ -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;
|
||||
}
|
||||
|
@ -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
|
||||
{
|
||||
|
@ -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
|
||||
|
Reference in New Issue
Block a user