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

Morph to Many using JoinRelationShipUsingAlias('relation_name') not working correctly #110

Open
JurjenRoels opened this issue Nov 7, 2022 · 1 comment

Comments

@JurjenRoels
Copy link

Hello,

I join the table attributes with a MoprhMany to lookups with lookupables. In attributes I create the relation in this way

return $this->morphToMany(Lookup::class, 'lookupable')->where('lookups.type', 'attribuut_datatype');

I call the powerjoinfunction: joinRelationshipUsingAlias, with only the name of the relation as a parameter

Powerjoin creates the following query:

inner join `lookupables` as `31816ced6e12347e02dbcd4865c7f779` on `31816ced6e12347e02dbcd4865c7f779`.`lookupable_id` = `attributen`.`id` 
inner join `lookups` as `52c1d48dd796b76bfe00982d5469c0d5` on `52c1d48dd796b76bfe00982d5469c0d5`.`id` = `31816ced6e12347e02dbcd4865c7f779`.`lookup_id` 
        and `52c1d48dd796b76bfe00982d5469c0d5`.`deleted_at` is null 
        and `lookupables`.`lookupable_type` = ? and `52c1d48dd796b76bfe00982d5469c0d5`.`type` = ?

As you can see. the lookupable_type is not using the alias.

Kind Regards
Jurjen

@JurjenRoels
Copy link
Author

Also When providing the alias manually, this is not working properly


->leftJoinRelationshipUsingAlias($field['foreignKey']['relation'], [
                                    'lookups' => function ($join) use($lookupAlias) {
                                        $join->as($lookupAlias);
                                    },
                                    'lookupables' => function ($join) use($lookupableAlias) {
                                        $join->as($lookupableAlias);                                    }
                                ]);

Result:

LEFT JOIN `lookupables` AS `attributen_is_sleutelveld_lookupables` ON `lookupables`.`lookupable_id` = `attributen`.`id`
  LEFT JOIN `lookups` AS `attributen_is_sleutelveld_lookups` ON `attributen_is_sleutelveld_lookups`.`id` = `lookupables`.`lookup_id`
 

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant