-
Notifications
You must be signed in to change notification settings - Fork 0
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
Automatic insertion of related entities #8
Comments
We could check whether any of the input attributes matches an Eloquent relation in the associated model. If so, we should be able to create and attach the related entity. We could even check what type of relation it is (belongsTo, hasMany...) and proceed as appropriate. How about validation though? @namelivia |
Yeah, that's a good way to proceed. Also the child entities should be validated, probably getting the validation rules from their models. |
Alright. I'm worried about the hit on performance due to the dynamic relationship lookup. Maybe we could use a more static approach, but this is more annoying for the developer: /* just came up with this, don't take it as something serious */
public function getRelatedEntities()
{
return ['foo' => Foo::class];
} |
I can't ensure that would be neccesary due to performance issues, maybe we should not worry that much. |
My approach is to get the class methods by using a ReflecionClass, however this can be used to determine if the method exists or not. Is this approach the one you were thinkin on @carlosafonso ? |
Yes. Either that or something like method_exists() |
I've been also thinking that way, the thing is guessing the type of relationship. |
That's a good one. Maybe we could rely on the PHPDoc annotations ( Or maybe this is just way too overkill and we're better off with a custom method that returns the accepted related entities. Maybe this is the easiest approach for now. |
And developers don't have to do anything if they don't want to use this feature. |
If there are two models,
Foo
andBar
, related so thatBar
belongs toFoo
, if the following input is received:Then the controller should automatically create the related entity
Bar
and associate it to the newly createdFoo
.The text was updated successfully, but these errors were encountered: