Repository navigation
Add forceCreate, forceUpdate, forceFill and Model.unguarded - #36
Merged
Merged
Conversation
A model update() on a query drops keys that fillable does not allow. There was no way to set a guarded column from a map. Add the Laravel force methods and Model.unguarded(). Query update() keeps the fillable check, so update(req.body) stays safe. A loaded model update() now sets updated_at.
Contributor
Author
Bot reviewVerdict: changes requested. The code looks right. One test gap blocks. Checks run: SQLite tests (531 passed), Blocking
What I checked and found OK
Nits
|
…on a guarded column The unguarded doc comment now says that work started inside the callback that finishes later also runs with the check off.
Contributor
Author
Fixer replyFixed the blocking items in 1eff26c.
Tests pass on SQLite, Postgres 16 and MariaDB 11. |
Contributor
Author
Bot reviewResult: no blocking issues. Ready to merge. Checked at 1eff26c:
Nits (do not block):
|
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Problem
A query
update()on a model drops keys thatfillabledoes not allow.So
User().where('id', 1).update({'is_admin': true})changes nothing and returns 0.With no
fillable, it throws.There was no way to set a guarded column from a map.
What changed
forceCreate(),forceUpdate()andforceFill(). They ignorefillableandguarded, like Laravel.Model.unguarded(() async { ... }). It turns the check off for every write inside the callback. It uses a zone, so other requests at the same time still usefillable.forceUpdate()is also on the query builder, so it works afterwhere(). OnQueryBuilder.table()it is the same asupdate().update({...})now setsupdated_at, like Laravel.Why query
update()keeps the fillable checkLaravel's query update ignores
fillable. Dox does not copy this.The docs and the doc comment show
User().where('id', 1).update(req.body).If the default changed, that code would let a user set
is_admin.So the default stays safe, and
forceUpdate()gives the Laravel behaviour.Tests
New tests in
test/security_test.dart.All tests pass on SQLite, Postgres 16 and MariaDB 11.
dart analyzeis clean.Docs PR: dartondox/dox (docs/force-fill).