Skip to content
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

Implement supplementary directives for all Eloquent relationship types #332

Open
10 of 11 tasks
spawnia opened this issue Sep 18, 2018 · 5 comments
Open
10 of 11 tasks
Labels
enhancement A feature or improvement

Comments

@spawnia
Copy link
Collaborator

spawnia commented Sep 18, 2018

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

  • hasMany
  • belongsTo
  • hasOne
  • belongsToMany
  • hasOneThrough
  • hasManyTrough
  • morphTo
  • morphOne
  • morphMany
  • morphToMany
  • morphedByMany
@spawnia
Copy link
Collaborator Author

spawnia commented Aug 30, 2019

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

@enzonotario
Copy link
Collaborator

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

@sascha1337
Copy link

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 ?

@lorado
Copy link
Collaborator

lorado commented Jul 8, 2020

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.

@sascha1337
Copy link

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

@spawnia spawnia changed the title Support other Eloquent relationships Implement supplementary directives for all Eloquent relationship types Jul 16, 2020
This was referenced Oct 30, 2020
@nuwave nuwave deleted a comment from mwangaben Dec 5, 2021
spawnia added a commit that referenced this issue Jul 4, 2022
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
enhancement A feature or improvement
Projects
None yet
Development

No branches or pull requests

4 participants