Skip to content

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

@illusi03

Description

@illusi03

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.

Metadata

Metadata

Assignees

No one assigned

    Labels

    enhancementNew feature or request

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions