Open os-nikita opened 2 years ago
I am not sure to see what you mean. Could you post a code snippet so that I can reproduce the issue ? 🙏
I think the way to replicate it is this:
Results in this error
The error seems clear to me and i'm not sure what you find confusing about it. I'll reopen and fix if you can provide a solution that makes sense to you
@josephmancuso
Here's what I mean. This throws an exception, rather than rendering the home view:
It's not about a calling a method on a model. It's about the fact that the model hasn't been persisted yet and attempting to access an attribute/property (not a method), will throw this error.
If I change the above slightly to the following, the error isn't thrown. The email is returned:
Ok so Ill add a possible solution like
Title: Model has not been created or retrieved
Solution: Make sure the model is correctly created or retrieved from the database before accessing attributes.
How you are going to differentiate a normal class from a model class ? Because it should be a solution for Masonite Model classes only... 🤔
If the model is brand new, hasn't been created yet (
not model.is_created() == True
), then trying to access a property on the model likeif not user.picture: ...
will result in this error. The solution offered can be confusing.