Skip to content

Commit

Permalink
Update Model.php
Browse files Browse the repository at this point in the history
  • Loading branch information
ulises-jeremias authored Nov 17, 2017
1 parent d9a0c64 commit 458560a
Showing 1 changed file with 12 additions and 12 deletions.
24 changes: 12 additions & 12 deletions Mbh/Model.php
Original file line number Diff line number Diff line change
Expand Up @@ -195,6 +195,18 @@ public static function update($e, $where = "1=1", $limit = "")

return static::$db->update(static::$table['name'], $e, $where, $limit);
}

public static function updateWith($data)
{
$column = array_search(static::$table['idColumn'], static::$columnData);
$class = get_called_class();
foreach ($data as $key => $value) {
$new_data = new $class($value);
if (!$new_data->refresh()->getStateAttr($column)) {
$new_data->save();
}
}
}

/**
* Selects and lists in an associative / numeric array the results of a search in the database
Expand Down Expand Up @@ -331,18 +343,6 @@ public function remove()
return $this;
}

public static function updateWith($data)
{
$column = array_search(static::$table['idColumn'], static::$columnData);
$class = get_called_class();
foreach ($data as $key => $value) {
$new_data = new $class($value);
if (!$new_data->refresh()->getStateAttr($column)) {
$new_data->save();
}
}
return $this;
}
public function __toString()
{
return json_encode($this->state);
Expand Down

0 comments on commit 458560a

Please sign in to comment.