Added related model updating from belongs_to relationship.

This commit is contained in:
Taylor Otwell
2012-03-17 23:14:01 -05:00
parent 68b4e55336
commit fcff36a0ac
4 changed files with 42 additions and 5 deletions

View File

@@ -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.
*