nestjs-paginate: Duplicate column errors

When running:

http://localhost:3000/job-positions?filter.user.id=$eq:bdTlIRyqqner&page=1

with

paginate(query, this.repo, {
  sortableColumns: [ 'company.name' ],
  searchableColumns: [],
  filterableColumns: { 'user.id': [ '$eq', '$in' ] },
  defaultLimit: 20,
  defaultSortBy: [ [ 'company.name', 'DESC' ] ],
  relations: [ 'user', 'company' ]
})

The following error arises:

[Nest] 23412  - 03/05/2023, 3:43:26 PM   ERROR [ExceptionsHandler] Duplicate column name 'e_user_id'
QueryFailedError: Duplicate column name 'e_user_id'

Inspecting the failed query shows that 2 columns e_user_id are generated, one from the filter user.id and the other from the column user_id:

SELECT DISTINCT `distinctAlias`.`e__id` AS `ids_e__id`,
                `distinctAlias`.`e_company_name`
FROM   (SELECT `e`.`_id`                    AS `e__id`,
               `e`.`id`                     AS `e_id`,
               `e`.`freelance`              AS `e_freelance`,
               `e`.`job_title`              AS `e_job_title`,
               `e`.`freelance_client`       AS `e_freelance_client`,
               `e`.`past`                   AS `e_past`,
               `e`.`user_id`                AS `e_user_id`,
               `e`.`company_id`             AS `e_company_id`,
               `e_user`.`_id`               AS `e_user__id`,
               `e_user`.`id`                AS `e_user_id`,
               `e_user`.`auth_subject`      AS `e_user_auth_subject`,
               `e_user`.`name`              AS `e_user_name`,
               `e_user`.`surname`           AS `e_user_surname`,
               `e_user`.`job_title`         AS `e_user_job_title`,
               `e_user`.`email`             AS `e_user_email`,
               `e_user`.`fiscal_code`       AS `e_user_fiscal_code`,
               `e_user`.`calendar_email`    AS `e_user_calendar_email`,
               `e_user`.`signup_date`       AS `e_user_signup_date`,
               `e_user`.`phone_number`      AS `e_user_phone_number`,
               `e_user`.`points`            AS `e_user_points`,
               `e_user`.`seniority`         AS `e_user_seniority`,
               `e_user`.`nation`            AS `e_user_nation`,
               `e_user`.`city`              AS `e_user_city`,
               `e_user`.`contactpreference` AS `e_user_contactPreference`,
               `e_user`.`freelancer`        AS `e_user_freelancer`,
               `e_user`.`corporate_worker`  AS `e_user_corporate_worker`,
               `e_user`.`platform_id`       AS `e_user_platform_id`,
               `e_user`.`role_id`           AS `e_user_role_id`,
               `e_company`.`_id`            AS `e_company__id`,
               `e_company`.`id`             AS `e_company_id`,
               `e_company`.`name`           AS `e_company_name`
        FROM   `job_position` `e`
               LEFT JOIN `user` `e_user`
                      ON `e_user`.`_id` = `e`.`user_id`
               LEFT JOIN `company` `e_company`
                      ON `e_company`.`_id` = `e`.`company_id`
        WHERE  ( `e_user`.`id` = ? )) `distinctAlias`
ORDER  BY `distinctAlias`.`e_company_name` DESC,
          `e__id` ASC
LIMIT  1 

Is this a user or library error? If itโ€™s a user error, how can I resolve it, and what can we do to catch this beforehand to raise a better error?

About this issue

  • Original URL
  • State: closed
  • Created a year ago
  • Comments: 18 (7 by maintainers)

Most upvoted comments

Fixed by my PR

The column collisions are fixed though ๐ŸŽ‰