How to pass dynamic values in find api

Hi Team,

how to pass dynamic values to find api

For example L

strapi.query('restaurant').find({ _limit: 10, id_in: [1, 2] });

right now i am passing static value to “id_in”.

I defined a variable to pass dynamic value.

For example

dynamic_values = “1,2”;

entity = strapi.query(‘restaurant’).find({ _limit: 10, id_in: [dynamic_values.split(’,’) ] });

I am getting run time error
[2020-10-28T11:08:31.082Z] error Error: SQLITE_ERROR: sub-select returns 2 columns - expected 1

Please advice.

Thanks!

When you use .split(’,’) it actually returns an array, so your query looks like: id_in: [[1,2]]

So the corrent query will be:

strapi.query(‘restaurant’).find({ _limit: 10, id_in: dynamic_values.split(’,’) });

Yes. Thanks . Corrected it.

Summary

An off topic, I’ve noticed that you don’t mark your topics with a Solution response. Please mark them if your problem is solved.

Sorry… got it. I have done

:joy:

You need to mark as solution the post where you actually found your solution, not your own post saying “corrected it”. This will help the rest of us to quickly go to the solution, see how your first post was modified after you marked the solution…

1 Like