-
Notifications
You must be signed in to change notification settings - Fork 13
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
Don't break with Model::shouldBeStrict()
enabled
#18
base: master
Are you sure you want to change the base?
Conversation
Model::shouldBeStrict()
` enabledModel::shouldBeStrict()
enabled
Does this PR address the same thing as this? protected static $modelsShouldPreventAccessingMissingAttributes = false; |
Yes and no. I have strict enabled project wide in dev, as is somewhat common. I would prefer strict stays enabled so the model behaves the same as everything else in my project, but there's some personal preference in there. |
Would need a more detailed description of what exactly this PR is solving then, the test doesn't add much info. |
Will in the AM |
In my case, I have Model::shouldBeStrict() enabled. Here's a quick explanation of the specific one that's causing this issue: For example, I do have this on my user model, and I would like to ensure that custom columns are indeed loaded. The issue is, I'm not able to do |
I see. The snippet I posted above is what we use in Tenancy for Laravel for use cases where you might do e.g.: if ($tenant->logo) { ... } as a sort of "has attribute" check. The case you're describing here is about models that haven't been saved to the DB yet? Or I guess when they're being created at first. Once they're pulled from the DB, the |
I'm purely running a the only attribute that is fetched by the database is the The test I wrote demonstrates that behaviour. |
I see now, so some ways of fetching the model completely omit the |
Actually just checking the column exists and returning early in the |
Can you expand on the behavior difference? What you mean by silently failing specifically, compared to the behavior after the change |
When you do a So the This change now checks if the data column exists before running |
An unintended behaviour of this is that you can accidentally wipe all the custom data from a column without being careful.
This would actually fail because only I've added a proof of concept that checks if the data was loaded from the database. There might be a better way to do it. |
That makes sense. So in the try-catch implementation, the Whereas now with the listener not being triggered, the Though then I don't get what the last change is for, I think I'm misunderstanding which implementation (if any) you're saying would prevent the |
The last change marks when you choose to selectively pull columns from the database, doesn't decode and prevents you from trying to write when the |
I'd be fine with not including the save side of things |
see this test for what is this fixes:
https://github.com/nick-potts/virtualcolumn/blob/bd7097323d3d6dc45e418363562bfc13b56bcce6/tests/VirtualColumnTest.php#L133