eloquent-power-joins icon indicating copy to clipboard operation
eloquent-power-joins copied to clipboard

Incorrect table name used when joining with an alias

Open jreason opened this issue 2 years ago • 0 comments

Hi,

I am using leftJoinRelationshipUsingAlias.

This simple example should return both table ids but w_id is returning null.

ConversionOptionsNew::optionType('wheel-style')
            ->active()
            ->inOrder()
            ->leftJoinRelationshipUsingAlias('wheelSize', 'wheel_size')
            ->select('conversion_options_new.id', 'wheel_size.id as w_id')
            ->get();

When using toSql() to print out the raw sql, i get the following sql:

SELECT
	`conversion_options_new`.`id`,
	`wheel_size`.`id` AS `w_id`
FROM
	`conversion_options_new`
LEFT JOIN `conversion_options_new` AS `wheel_size` ON `wheel_size`.`id` = `wheel_size`.`wheel_size_id`
WHERE
	`conversion_options_new`.`option_type` = 'wheel-style'
AND `conversion_options_new`.`active` = '1'
ORDER BY
	`conversion_options_new`.`order` ASC

When changing the following line and testing, i then get the correct result.

LEFT JOIN conversion_options_new AS wheel_size ON wheel_size.id = conversion_options_new.wheel_size_id

jreason avatar Mar 29 '22 13:03 jreason