Added related model updating from belongs_to relationship.
This commit is contained in:
@@ -174,6 +174,22 @@ abstract class Model {
|
||||
return ($success) ? $model : false;
|
||||
}
|
||||
|
||||
/**
|
||||
* Update a model instance in the database.
|
||||
*
|
||||
* @param mixed $id
|
||||
* @param array $attributes
|
||||
* @return int
|
||||
*/
|
||||
public static function update($id, $attributes)
|
||||
{
|
||||
$model = new static(array(), true);
|
||||
|
||||
if (static::$timestamps) $attributes['updated_at'] = $model->get_timestamp();
|
||||
|
||||
return $model->query()->where($model->key(), '=', $id)->update($attributes);
|
||||
}
|
||||
|
||||
/**
|
||||
* Find a model by its primary key.
|
||||
*
|
||||
|
||||
Reference in New Issue
Block a user