Friday, May 17, 2024
 Popular · Latest · Hot · Upcoming
82
rated 0 times [  84] [ 2]  / answers: 1 / hits: 12610  / 4 Years ago, wed, july 1, 2020, 12:00:00

Hope you are all having a nice day! :)
I have tried to google my question but never can get a working example.


I have a model for Projects. Projects has a 1:n relationship with the model Members.
If I use:


strapi.query('project').find({id: 1});

I get:


{ id: 1, name: 'Project 1', members: [...]}

So basically I am able to find a Project by its ID and I get a list of its Members.


BUT how would I go about getting a list of all members that belong to Project with ID = 1?


strapi.query('member').find(...);
strapi.query('member').search(...);

The closest I got was using:


strapi.query('member').search({_q: 'Project Name'});

This is however not close enough. It is more of a work around. I would really like to be able to do this in a clean way by using the IDs of the Project. Can anyone help or point me in the right direction? Any examples are greatly appreciated! Thank you! :)


More From » strapi

 Answers
16

The best way to do this is:


strapi.query('member').find({name:'','project.id':id});

Above is AND find


strapi.query('member').find({name:''},['project.id',id]);

Above is OR find


[#3317] Sunday, June 28, 2020, 4 Years  [reply] [flag answer]
Only authorized users can answer the question. Please sign in first, or register a free account.
alorac

Total Points: 262
Total Questions: 82
Total Answers: 97

Location: Libya
Member since Mon, Dec 7, 2020
4 Years ago
alorac questions
Sat, Oct 10, 20, 00:00, 4 Years ago
Tue, Sep 22, 20, 00:00, 4 Years ago
Wed, Jun 3, 20, 00:00, 4 Years ago
Sun, May 17, 20, 00:00, 4 Years ago
Wed, Mar 4, 20, 00:00, 4 Years ago
;