protected static function refreshModel(RedBeanModel &$model) { assert('$model->id > 0'); // this is just a fail safe. We don't want to lose any unsaved changes. // ideally $model should be saved by this point anyway, but regardless: if ($model->isModified() && !$model->save()) { throw new FailedToSaveModelException(); } $modelId = $model->id; $modelClass = get_class($model); $model->forgetAll(); $model = $modelClass::getById($modelId); }