lighthouse icon indicating copy to clipboard operation
lighthouse copied to clipboard

Implement supplementary directives for all Eloquent relationship types

Open spawnia opened this issue 7 years ago • 5 comments

Is your feature request related to a problem? Please describe.

Many users have come up with use cases where they require some of the other relationship types of Eloquent, such as Polymorphic relationships or Pivot Relations. In many cases, they work fine without any directives or do also work when using @belongsTo or @hasMany, although edge cases do come up from time to time.

To clarify: Other relationship types still work without those directives. They can simply be declared as fields on the type without using any directives.

Describe the solution you'd like

Implement additional directives for Eloquent's other relationship types. I am sure we can do some nice optimizations and make Lighthouse even more simple to use.

https://laravel.com/docs/eloquent-relationships#defining-relationships

Support

  • [x] hasMany
  • [x] belongsTo
  • [x] hasOne
  • [x] belongsToMany
  • [x] hasOneThrough
  • [x] hasManyTrough
  • [x] morphTo
  • [x] morphOne
  • [x] morphMany
  • [x] morphToMany
  • [ ] morphedByMany

spawnia avatar Sep 18 '18 21:09 spawnia

@enzonotario have you started work on @morphOne and @morphMany? I would like to get those in before the next release.

spawnia avatar Aug 30 '19 11:08 spawnia

not yet, but I can work on that this weekend!

enzonotario avatar Aug 30 '19 14:08 enzonotario

I would like to get the Roles of my UserModel, im using spatie/laravel-permissions. It's adding a roles() method with return MorphToMany. How would you guys put the reverse into the Schema - morphedByMany as inverse ? Documentation does not show this directive, but there is a Model in the Tests using morphedByMany here: https://github.com/nuwave/lighthouse/blob/36552f2886296d0e324c3482b5cef155a53b9501/tests/Utils/Models/Tag.php

Any clue ? When @morphedByMany implementation ?

sascha1337 avatar Jul 08 '20 12:07 sascha1337

Could you try @belongsToMany? It works somehow, however I didn't look into the code, so don't know how it exactly works.

You can currently fetch the data also without directive, but you will not have performance benefits from data loaders, as every field will be resolved separately, means every time laravel goes to DB.

lorado avatar Jul 08 '20 12:07 lorado

Sounds like a workaround, would be amazing to get this fixed / implemented :-)

sascha1337 avatar Jul 15 '20 08:07 sascha1337