Join GitHub today
GitHub is home to over 40 million developers working together to host and review code, manage projects, and build software together.Sign up
Refresh model attributes after a save operation #2012
It is often necessary to get all the attributes from the database immediately after a save. The current behavior is also not very intuitive, where after a save some attributes will be set but not others. For example, the timestamp columns might be missing entirely if the user didn't set them manually (#507).
This should lead to a much better experience when working with models, since the model will always have the most up-to-date attributes without needing to manually call
This will call
Note that the after save event signatures were changed to make them more consistent. Namely the second argument was removed since it wasn't very useful in any case (for update events it was always
Current PR Issues
Requires two queries on database that do not support
- This makes them more accurate when working with MySQL that doesn't support millisecond timestamp columns by default when used with Knex.
- Previously any method that called _doFetch() would get the previous attributes reset, but we don't want to do this when calling refresh from the save method.
- With the recent change of refreshing the model after save both the `this` and `updatedModel` were the same thing. - This change also makes all the "after" save events more consistent since the arguments are all the same. - Finally, the previous values returned as the second argument just weren't very useful and the id of the inserted model is available in the updated model, so no data is lost.