orm icon indicating copy to clipboard operation
orm copied to clipboard

Ошибка в join()

Open only-viktor opened this issue 4 years ago • 1 comments

Пример запроса:

$userRepository
  ->select()
  ->buildQuery()
  ->join('LEFT', 'user_profile', 'profile', 'user.id = profile.user_id')
  ->fetchAll()

В запросе получается вот такой JOIN:

LEFT JOIN "user_profile" AS "profile"
    ON "profile" = "user"."id" = "profile"."user_id" 

Проблема в том, что в методе JoinTrait:join(), передается параметр $alias в аргументы метода JoinTrait::on(...$args). Поэтому получается ошибка в запросе JOIN, лишний параметр "profile" =

only-viktor avatar Mar 25 '21 11:03 only-viktor

Рекомендую использовать отдельный метод ->on():

$userRepository
  ->select()
  ->buildQuery()
  ->join('LEFT', 'user_profile as profile')
  ->on(['user.id' => 'profile.user_id'])
//  так тоже работает:
//  ->on('user.id', 'profile.user_id')
  ->fetchAll()

roxblnfk avatar Mar 25 '21 15:03 roxblnfk