fix(laravel): Allow LinksHandler to handle polymorphic relationships#7231
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.
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.
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.
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.