Adrinalin4ik / Nestjs-Graphql-Tools

NestJS Graphql Tools is a flexible solution that provides a bunch of decorators for solving problems like n+1 request, filtering, sorting, pagination, polymorphic relation, graphql field extraction. It is fully based on decorators. To use it you can just add a decorator to your resolver.
GNU General Public License v3.0
79 stars 8 forks source link

Resolving Ambiguity: Handling Column Ambiguity Error in Multi-Table Product Query with Status Filter #25

Closed thejaydev closed 1 year ago

thejaydev commented 1 year ago

Describe the bug Suppose we have tree table product, category, and product type tables in all three tables containing field name status. So while I fetch products with category and product type using setFindOption with relation category and product type and apply filter. In this case, if the user tries to fetch the products by status using a filter they got the error of column status is ambiguous. The reason behind this error is that filter variables do not attach any table preference in query building so that is why the SQL database cause an error.

image

Adrinalin4ik commented 1 year ago

Hey @jaydev-01 . Please read documentation in the filters section. You can define custom filters by multiple entities in the case you have many joins. In your case you can try to use sqlAlias as the parameter of @filter decorator. The same thing works for the sorting. When you're creating query builder pass the same alias so filter's sql alias would match what you pass to query builder.

thejaydev commented 1 year ago

Thank you for your help @Adrinalin4ik

Adrinalin4ik commented 1 year ago

Sure, no problem. Don't hesitate to ask me any questions.