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

M20 filtered area aggregation and groupBy ambiguous #10092

Closed
3 tasks done
ahmtaras opened this issue Nov 26, 2021 · 2 comments · Fixed by #10250
Closed
3 tasks done

M20 filtered area aggregation and groupBy ambiguous #10092

ahmtaras opened this issue Nov 26, 2021 · 2 comments · Fixed by #10250
Assignees
Labels
Milestone

Comments

@ahmtaras
Copy link

ahmtaras commented Nov 26, 2021

Preflight Checklist

Describe the Bug

I am trying to aggregate and group by filtering from M2O field. But I am getting the below mentioned error.

To Reproduce

const { data } = await this.$sdk.items("records").readMany({
  fields: ["id", "type", "price", "current.name"],
  filter: {
    current: {
      name: {
        _contains: "Ahmet",
      },
    },
  },
  groupBy: ["type"],
  aggregate: {
    sum: "price",
  },
});

Errors Shown

{
  "errors": [{
    "message": "select \"records\".\"type\", sum(\"records\".\"price\") as \"sum->price\" from \"records\" left join \"currents\" as \"czbsb\" on \"records\".\"current\" = \"czbsb\".\"id\" where \"czbsb\".\"name\" like $1 group by \"type\" order by \"records\".\"type\" asc limit $2 - column reference \"type\" is ambiguous",
    "extensions": {
      "code": "INTERNAL_SERVER_ERROR"
    }
  }]
}

What version of Directus are you using?

9.1.2

What version of Node.js are you using?

16.13.0

What database are you using?

PostgreSQL 14.0, compiled by Visual C++ build 1914, 64-bit

What browser are you using?

Chrome

What operating system are you using?

Windows_NT 10.0.22000

How are you deploying Directus?

locally

@ahmtaras ahmtaras changed the title Filter M20 groupBy ambiguous M20 filtered area aggregation and groupBy ambiguous Nov 26, 2021
@azrikahar
Copy link
Contributor

@ahmtaras just to confirm, both records and currents collections have a column named type in them? This should be detailed in the To Reproduce section, as that is the key element of reproducing this 👍


Note for possible fix:

Judging from the generated SQL query in the error message, seems like groupBy doesn't have a table prefix, but orderBy has it. Likely due to order by uses getColumn() function to get the prefix:

column: getColumn(knex, collection, column, false) as any,

whereas group by just returns the column (if it's not a function):

@ahmtaras
Copy link
Author

ahmtaras commented Nov 30, 2021

@azrikahar yes, both collections have a column named type. I think the problem is name conflict. But there must be another way. I tried alias but same problem with it.

Parent Collection Currents

id
name
type -> supply || customer || special
records -> O2M

Child Collection Records

id
price
type -> money_in || money_out || sales_invoice || purchase_invoice
current -> M2O

@rijkvanzanten rijkvanzanten self-assigned this Dec 3, 2021
@rijkvanzanten rijkvanzanten added this to the v9.1.3 milestone Dec 3, 2021
rijkvanzanten added a commit that referenced this issue Dec 3, 2021
rijkvanzanten added a commit that referenced this issue Dec 3, 2021
@github-actions github-actions bot locked as resolved and limited conversation to collaborators Feb 2, 2024
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
Projects
None yet
Development

Successfully merging a pull request may close this issue.

3 participants