-
Notifications
You must be signed in to change notification settings - Fork 102
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
Use parent's fillables in children models #77
Comments
I created a PR for this so the code can be more easily visualized and/or tested. I did not yet add any tests, as I'd rather first finalize the feature, and then discuss the best testing scenarios to cover in the Unit Tests. |
Thanks @litvinjuan for your work. I came across this ticket after noticing the same behaviour when using It looks like this will also apply to |
Hey friends! The team at Tighten has taken Parental back over and we're re-opening the issue tracker, but to give us a clean slate, I'm going to close all old issues that remain from when Caleb closed the issue tracker in 2020. If this is still an outstanding concern with the latest version of Parental, please feel free to open a new issue referencing this one. Thank you! |
When you create a parent model that has some fillable attributes and later have a child model that extends that, the child model needs to duplicate its parent's fillable attributes. In the following example, a User has a name and email, and a spy is a type of user that also has a secret_spy_id. Currently, if I do Spy::create(['name' => 'MikeSpy' ...]), I will get an exception about the name and email NOT NULL constraints being violated. This is, because Spy does not recocnize name or email as fillable attributes, and thus does not populate the fields or reflect that to the database. The following are the example classes:
The above won't work unless we do the following:
I imagine fixing this by adding a method in HasParent that overrides Model::getFillable() and returns a merge of $this->fillable and the parent's getFillable() method. This method would look like this:
The text was updated successfully, but these errors were encountered: