Skip to content
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

Entity null values cause database error #1992

Closed
MGatner opened this issue May 7, 2019 · 5 comments
Closed

Entity null values cause database error #1992

MGatner opened this issue May 7, 2019 · 5 comments
Assignees

Comments

@MGatner
Copy link
Member

MGatner commented May 7, 2019

Issue #1773 needed null values to be included in model verification, but by using all values from classToArray (instead of $onlyChanged) Model->save() now attempts to insert null entity values into the database, which will throw an exception for columns that cannot be null.

I think save() should still use only changed values and validation should be updated to check for non-existent required values. Also, I believe #1930 passed tests because tests/system/Database/Live/ModelTest.php (e.g. testSaveNewEntityWithDate()) is defining all field values, which is non-mandatory.

@lonnieezell
Copy link
Member

You're right that save() should only used changed fields during updates, but all fields should be used if it's an insert, I would think. I'm not sure off the top of my head how to know which fields are allowed nullable during insert and which should be ignored if they are null, without adding an additional layer of complexity for everyone, which I don't want to do.

@lonnieezell
Copy link
Member

We're hitting some complex issues here that I think are going to require a refactor of Entities. On the plus side, I think it'll make them more robust. My plan is to make them work a little more like Laravel's Models insofar as you don't have to specify properties anymore. We'll keep two protected properties - original and attributes that store the original attributes and the current attributes. It should simplify some other usage issues I've been struggling with for a while.

Unfortunately, that means that anyone who's built anything already will have to refactor, but that's the fun of pre-release software I guess.

@lonnieezell lonnieezell self-assigned this May 10, 2019
@MGatner
Copy link
Member Author

MGatner commented May 10, 2019

I love it! Always worth it to stop and redo something the right way.

Let me know how I can help.

@nowackipawel
Copy link
Contributor

nowackipawel commented May 10, 2019 via email

@lonnieezell
Copy link
Member

@MGatner I got through about 80% of the required changes last night, I believe. So shouldn't take too long to get switched over. Thanks, though!

@nowackipawel Unrelated to Entities.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants