Harmonisation of MorphToMany relationship query building #50302
Unanswered
stephaneisenbach
asked this question in
Ideas
Replies: 0 comments
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Uh oh!
There was an error while loading. Please reload this page.
-
I had trouble with the union of two MorphToMany queries.
I need to set up a method (MorphToMany relation) that should return the related models in a bidirectional way, that is, the method should return the MorphToMany relations as well as the MorphedByMany relations, which are actually just inverse MorphToMany relations.
This should be possible in my case because the related models are of the same class.
Table Structure
I have set up a method
Contact->relatedTestContacts()
in order to get a collection of contacts in a relationship of the given type 'test' (bidirectional). Thecontactables.type
attribute is used as a pivot field to distinguish between different types of relationship.This method is used in a Laravel Nova installation ("laravel/framework": "^10.10", "laravel/nova": "^4.0") for a
Laravel\Nova\Fields\MorphToMany
Field as described here: https://nova.laravel.com/docs/resources/relationships.html#morphtomany.The method looked like this:
This has resulted in the following error.
The selected columns of the two MorphToMany relations differ, which (in my opinion) should be identical. The second select uses only '*' for all columns.
My dirty workaround:
Idea: Harmonise the building of select queries at Builder level so that both select the same columns. This would make it possible to union selects of the same class.
Beta Was this translation helpful? Give feedback.
All reactions