Compare commits
4 Commits
Author | SHA1 | Date | |
---|---|---|---|
8531658899 | |||
f19385ccc1 | |||
02f8bb0b4f | |||
d3771d8844 |
@ -150,25 +150,26 @@ abstract class Repository implements RepositoryInterface
|
|||||||
public function fillData(Model $model, array $data): Model
|
public function fillData(Model $model, array $data): Model
|
||||||
{
|
{
|
||||||
foreach ($this->getRequired() as $column) {
|
foreach ($this->getRequired() as $column) {
|
||||||
$m = 'set' . ucwords($column);
|
$m = $this->getMethod($column, false);
|
||||||
$model->{$m}($data[$column]);
|
$model->{$m}($data[$column]);
|
||||||
}
|
}
|
||||||
foreach ($this->getOptional() as $column) {
|
foreach ($this->getOptional() as $column) {
|
||||||
if (isset($data[$column])) {
|
if (!isset($data[$column])) {
|
||||||
$m = 'set' . ucwords($column);
|
continue;
|
||||||
$model->{$m}($data[$column]);
|
|
||||||
}
|
}
|
||||||
|
$m = $this->getMethod($column, false);
|
||||||
|
$model->{$m}($data[$column]);
|
||||||
}
|
}
|
||||||
return $model;
|
return $model;
|
||||||
}
|
}
|
||||||
public function mapArray(Model $model, array $data): array
|
public function mapArray(Model $model, array $data): array
|
||||||
{
|
{
|
||||||
foreach ($this->getColumns() as $column) {
|
foreach ($this->getColumns() as $column) {
|
||||||
$m = $this->getMethod($column);
|
|
||||||
$val = $model->{$m}();
|
|
||||||
if (isset($data[$column])) {
|
if (isset($data[$column])) {
|
||||||
continue;
|
continue;
|
||||||
}
|
}
|
||||||
|
$m = $this->getMethod($column);
|
||||||
|
$val = $model->{$m}();
|
||||||
$data[$column] = $val;
|
$data[$column] = $val;
|
||||||
}
|
}
|
||||||
return $data;
|
return $data;
|
||||||
@ -215,7 +216,7 @@ abstract class Repository implements RepositoryInterface
|
|||||||
{
|
{
|
||||||
foreach ($this->getColumns() as $col) {
|
foreach ($this->getColumns() as $col) {
|
||||||
if (isset($data[$col])) {
|
if (isset($data[$col])) {
|
||||||
$m = 'set' . ucwords($col);
|
$m = $this->getMethod($col, false);
|
||||||
$model->{$m}($data[$col]);
|
$model->{$m}($data[$col]);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@ -232,7 +233,7 @@ abstract class Repository implements RepositoryInterface
|
|||||||
$query = $this->getQueryBuilder()
|
$query = $this->getQueryBuilder()
|
||||||
->select()
|
->select()
|
||||||
->from($this->getTable())
|
->from($this->getTable())
|
||||||
->where([['id', '?']])
|
->where(['id = ?'])
|
||||||
->limit(1);
|
->limit(1);
|
||||||
return $this->load($this->getConnection()->execute($query, [$id])->getAsArray()[0]);
|
return $this->load($this->getConnection()->execute($query, [$id])->getAsArray()[0]);
|
||||||
}
|
}
|
||||||
|
Reference in New Issue
Block a user