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

Duplicated column when using .withAggregate and .groupLimit in the same preload #933

Closed
Liviaparaujo opened this issue May 25, 2023 · 1 comment
Labels
Status: Abandoned Dropped and not into consideration

Comments

@Liviaparaujo
Copy link

Package version

18.3.0

Node.js and npm version

16.16.0, 8.11.0

Sample Code (to reproduce the issue)

The query in question:

 const columnsQuery = await board
      .related('columns')
      .query()
      .orderBy('position', 'asc')
      .preload('cards', (query) => {
            query.withAggregate('cardChecklistContent', (subQuery) => {
            subQuery.count('card_checklist_contents.id')
            subQuery.as('allContent')
          })
          query.groupOrderBy('position', 'asc').groupLimit(30)
      })

It generates the SQL query:

SELECT *
FROM
  (SELECT `cards`.*,
          `board_column_id`,

     (SELECT count(`card_checklist_contents`.`id`)
      FROM `card_checklist_contents`
        AND (`cards`.`id` = `card_checklist_contents`.`card_id`)) AS `allContent`,
          row_number() OVER (PARTITION BY board_column_id
                             ORDER BY POSITION ASC) AS adonis_group_limit_counter
   FROM `cards`
     AND (`board_column_id` in (417,
                                157,
                                158,
                                159,
                                160))) AS `adonis_temp`
WHERE `adonis_group_limit_counter`  <= 30

and the error ER_DUP_FIELDNAME: Duplicate column name 'board_column_id'. The error occurs because board_column_id is a column from the Cards model. The query runs fine without the groupLimit and also if I chage the .withAggregate for a preload

@stale
Copy link

stale bot commented Aug 12, 2023

This issue has been automatically marked as stale because it has not had recent activity. It will be closed if no further activity occurs. Thank you for your contributions.

@stale stale bot added the Status: Abandoned Dropped and not into consideration label Aug 12, 2023
@stale stale bot closed this as completed Sep 17, 2023
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Status: Abandoned Dropped and not into consideration
Projects
None yet
Development

No branches or pull requests

1 participant