feat: add insert-only fields to Model#10350
Open
memleakd wants to merge 2 commits into
Open
Conversation
- add $insertOnlyFields and setInsertOnlyFields() to Model - prevent configured fields from being submitted during update operations - allow insert-only fields during insert and insertBatch - document the Model-level protection boundaries - add coverage for update, save, updateBatch, entity, and protect(false) paths Signed-off-by: memleakd <121398829+memleakd@users.noreply.github.com>
Signed-off-by: memleakd <121398829+memleakd@users.noreply.github.com>
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.
Description
This adds
$insertOnlyFieldsto Model.The goal is to allow fields that can be set when a row is created, but should not be submitted later through Model update operations. This can be useful for values like public IDs, external references, generated slugs, or similar fields that should normally stay unchanged after insert.
Example:
With this configuration,
public_idis allowed duringinsert()andinsertBatch(), butupdate(),updateBatch(), and update-sidesave()will throw aDataExceptionif the field is submitted.This is only Model-level protection. It does not create a database constraint, does not inspect previous database values, and does not affect direct Query Builder writes. Calling
protect(false)disables this protection, the same as other field protection.I also added
setInsertOnlyFields()for cases where the list needs to be changed at runtime.Tests cover insert, insertBatch, update, save, set/update, updateBatch, entity updates, validation order, and
protect(false).Checklist: