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

[Feature] Flexibility joinRelationship with Initial Model. For some case Support MorphTo joins Nested. #197

Open
illusi03 opened this issue Jan 27, 2025 · 1 comment
Labels
enhancement New feature or request

Comments

@illusi03
Copy link

Dear Maintainers,

I hope this message finds you well. I am very excited and interested in enhancing the functionality of this package. I have been following the development of Eloquent Power Joins, and I am truly impressed by its ability to simplify and optimize complex database queries in Laravel.

Unfortunately, I am facing a problem where I can't perform a nested join in a MorphTo relationship.

For error nested example :

->joinRelationship(
    'medicalRecordable.creator',
    morphable: Customer::class,
)

The above code doesn't work. I understand that the morphable parameter can cause confusion when dealing with nested relationships. Therefore, I took the initiative to improve the joinRelationship() function to make it more flexible.

Improved example :

->joinRelationship(
    'medicalRecordable',
    morphable: Customer::class,
)
->joinRelationship(
    'creator',
    initialModel: User::class,
)

The above code works seamlessly. I would like to create a Pull Request based on this issue.
I am open to discussion if anyone has a better solution.
Thanks a lot.

illusi03 added a commit to illusi03/eloquent-power-joins that referenced this issue Jan 27, 2025
@luisdalmolin
Copy link
Member

Hmm, I do understand your issue, but I'm not sure I'm a big fan of yet another parameter without a lot of meaning. Wouldn't this be the case where morphable needs to work in nested relationships?

Something like:

->joinRelationship(
    'medicalRecordable.creator',
    ['creator' => fn ($join) => $join->morphable(Customer::class),
)

@luisdalmolin luisdalmolin added the enhancement New feature or request label Feb 12, 2025
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
enhancement New feature or request
Projects
None yet
Development

No branches or pull requests

2 participants