Compare commits
4 Commits
ba3c70a70e
...
2.4.2
Author | SHA1 | Date | |
---|---|---|---|
b19654bc70 | |||
fe67519682 | |||
0af6be2c8e | |||
0a9bed1735 |
@ -78,7 +78,7 @@ abstract class Model implements ModelInterface
|
|||||||
if ($method->getName() === 'getRepository') {
|
if ($method->getName() === 'getRepository') {
|
||||||
continue;
|
continue;
|
||||||
}
|
}
|
||||||
$p = strtolower(str_replace('get', '', $method->getName()));
|
$p = strtolower(preg_replace('/(?<!^)[A-Z]/', '_$0', str_replace('get', '', $method->getName())));
|
||||||
if (!isset($this->{$p})) {
|
if (!isset($this->{$p})) {
|
||||||
continue;
|
continue;
|
||||||
}
|
}
|
||||||
|
@ -109,6 +109,9 @@ abstract class Repository implements RepositoryInterface
|
|||||||
return $mapping->column;
|
return $mapping->column;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
if (in_array($property, $this->getColumns())) {
|
||||||
|
return $property;
|
||||||
|
}
|
||||||
throw new \InvalidArgumentException("Property {$property} not found in mapping in " . get_called_class());
|
throw new \InvalidArgumentException("Property {$property} not found in mapping in " . get_called_class());
|
||||||
}
|
}
|
||||||
public function findPropertyByColumn(string $column): string
|
public function findPropertyByColumn(string $column): string
|
||||||
@ -118,6 +121,9 @@ abstract class Repository implements RepositoryInterface
|
|||||||
return $mapping->property;
|
return $mapping->property;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
if (in_array($column, $this->getProperties())) {
|
||||||
|
return $column;
|
||||||
|
}
|
||||||
throw new \InvalidArgumentException("Column {$column} not found in mapping in " . get_called_class());
|
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) {
|
} catch (\InvalidArgumentException $e) {
|
||||||
continue;
|
continue;
|
||||||
}
|
}
|
||||||
|
if (isset($data[$column])) {
|
||||||
|
continue;
|
||||||
|
}
|
||||||
$m = $this->getMethod($property);
|
$m = $this->getMethod($property);
|
||||||
if (!method_exists($model, $m)) {
|
if (!method_exists($model, $m)) {
|
||||||
continue;
|
continue;
|
||||||
@ -277,7 +286,7 @@ abstract class Repository implements RepositoryInterface
|
|||||||
$values = $this->mapArray($model, []);
|
$values = $this->mapArray($model, []);
|
||||||
$cols = array_fill(0, count($values), '?');
|
$cols = array_fill(0, count($values), '?');
|
||||||
$query = $this->getQueryBuilder()->insert($this->getTable())->columns($this->getColumns())->values($cols);
|
$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
|
public function update(Model $model): void
|
||||||
{
|
{
|
||||||
|
@ -215,7 +215,7 @@ interface Repository
|
|||||||
public function fillData(Model $model, array $data): Model;
|
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 Model $model
|
||||||
* @param array $data
|
* @param array $data
|
||||||
* @return array
|
* @return array
|
||||||
|
Reference in New Issue
Block a user