Skip to content

Fixes issues when doing an 'IN' query#2156

Merged
lauriejim merged 2 commits into
strapi:masterfrom
greatwitenorth:patch-1
Oct 22, 2018
Merged

Fixes issues when doing an 'IN' query#2156
lauriejim merged 2 commits into
strapi:masterfrom
greatwitenorth:patch-1

Conversation

@greatwitenorth
Copy link
Copy Markdown
Contributor

When doing an 'IN' query it looks like this will incorrectly loop over the values and put them into multiple where clauses. This additional check on the symbol should leave the array untouched and pass it on into the orm for processing.

My PR is a:

🐛 Bug fix

Main update on the:

Framework

When doing an 'IN' query it looks like this will incorrectly loop over the values and put them into multiple where clauses. This additional check on the symbol should leave the array untouched and pass it on into the orm for processing.
@lauriejim
Copy link
Copy Markdown
Contributor

Hello @greatwitenorth , thank you for this PR.

Not sure to completely understand what you want.
Can you give me the issue you fix (and steps to reproduce).

@lauriejim lauriejim self-assigned this Oct 18, 2018
@lauriejim lauriejim added pr: 🐛 Bug fix source: core:strapi Source is core/strapi package labels Oct 18, 2018
@greatwitenorth
Copy link
Copy Markdown
Contributor Author

Consider the following custom method in a controller file:

api/product/controllers/Product.js

  findById: async (ctx) => {
    const ids = ctx.query.ids.split(',');
    return strapi.services.product.fetchAll({id_in: ids});
  },

and the following added to routes:

    {
      "method": "GET",
      "path": "/product/findById",
      "handler": "Product.findById",
      "config": {
        "policies": []
      }
    },

Currently a call to /product/findById?id=1,2,3 results in a 500 error:

You have an error in your SQL syntax; check the manual that corresponds to your MariaDB server version for the right syntax to use near ''1' and `id` in '2' and `id` in '3' limit 100' at line 1"

The following SQL is produced which is incorrect:

"select `products`.* from `products` where `id` in '1' and `id` in '2' and `id` in '3' limit 100"

With the proposed change, the system works as intended and returns products with ID 1,2,3.

@lauriejim lauriejim self-requested a review October 19, 2018 09:40
@lauriejim lauriejim added this to the 3.0.0-alpha.14.4 milestone Oct 19, 2018
Copy link
Copy Markdown
Contributor

@lauriejim lauriejim left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Good ! Thank you for this fix !

@lauriejim lauriejim merged commit 332533f into strapi:master Oct 22, 2018
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

source: core:strapi Source is core/strapi package

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants