New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
__fillable__ and __guarded__ are mutually exclusive... why? #846
Comments
Looks like this came in as part of #830 Though looking throught the Orator docs and current code base I cannot seem to find any reference to these attributes being mutually exclusive? @stoutput can you please provide an explanation? Happy to discuss further to get better understanding. |
Hey @circulon! There's really no need to specify both. One is a blocklist, one is an allowlist. From the docs: The The reason |
@stoutput I was considering the design / description of the Model itself so apologies for the confusion. So it looks like the docs need a little clarification added around this... I will have a look at that later. Happy to discuss further if you like. |
i think this is resolved now from he last reply from @stoutput which makes sense to me |
Describe the bug
Currectly (in v 2.19.1) cannot specify both fillable and guarded in a model together.
The documentation here: https://orm.masoniteproject.com/models#mass-assignment
implies (to me) that its ok.
if used together in the same model the following exception is raised when the model is instantiated.
SomeModel must specify either __fillable__ or __guarded__ properties, but not both.
This kind of defeats the purpose of being able to filter fields explicitly for different scenarios where they should or should not be mass assigned.
Additionally the
Model.filter_mass_assignment()
method actually uses both these attributesSo my question is, is this a design choice or is this error a false negative bug where the idea could have been possibly to check a column name cannot be in both
__fillable__
and__guarded__
at the same time?The Scenario where both these would be used is during a create followed by an update or explicit
.save()
so the guarded columns could not be accidently changed usinf mass assignment.
To Reproduce
Create a model that contains fillable and guarded
Instantiate the model
Expected behavior
Expect the model to be instantiated.
Desktop (please complete the following information):
What database are you using?
The text was updated successfully, but these errors were encountered: