-
-
Notifications
You must be signed in to change notification settings - Fork 918
fix(laravel): Allow LinksHandler
to handle polymorphic relationships
#7231
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
Conversation
71f4770
to
dc53b75
Compare
@soyuka in the first commit, I addressed the underlying issue. In the second commit, I am posposing a better way to handle links - using the built in standard eloquent relationship methods. By simply hydrating the base class with its identifier |
0c30958
to
997fec0
Compare
$relationQuery = $relation->{$from}(); | ||
if (!method_exists($relationQuery, 'getQualifiedForeignKeyName') && method_exists($relationQuery, 'getQualifiedForeignPivotKeyName')) { | ||
/** @var Model $relatedInstance */ | ||
$relatedInstance = $this->application->make($link->getFromClass()); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This line makes me think about #7166, its another subject but do you have any idea on how we could do otherwise to instantiate this class?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I think what needs to happen in the item/collection provider or property accessor is something like loadMissing
on the relations that are discovered through the eloquent property metadata service. This error happens when calling a relation that hasn't already been hydrated in the class. By calling loadMissing
we can hopefully prevent that. I'll play around with it and see what I can come up with.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Actually, we don't need to do anything anymore. This switched fix #7166 as well. See #7166 (comment)
This is awesome thank you very much @jonerickson ! |
This PR adds support for polymorphic relationships from within the
LinksHandler
.Previously:
This would result in bad query formation where the model type was not taken into account and you could have multiple model types returned with the same IDs:.
select * from `attachments` where `attachments`.`model_id` = ?
Now:
We now properly scope the query to the model class as well.