What I'm trying to do here is basically a mix of what was suggested for this question
User.count().where({follower: followerId})
and this question:
sails.models['user_phones__phone_users'].count({user_phones: userId}).exec(...)
So in other words I have a situation where I have three models: A, B and C. B acts as a Through association between A and C.
If I have a route that is basically A/:id/C?D=1&E=2
How can I get the results of C that are associated with A (through B) and match the filter of the query string (on D and E)?
At the moment it looks like count() works only with one model, but is there a workaround for this situation?
I know one idea would be to use a find (on A) with a populate (on C) and then count the populated associations, but in my case I have too many records and this solution kills the performance.
EDIT:
Filter criteria D and E apply to C. So they should be traslated to C.D=1 AND C.E=2 in SQL.
Also A and C are associated trough code:
// Model A
{
attributes: {
cs: {
collection: 'C',
via: 'as',
through: 'b'
},
}
}
// Model B
{
attributes: {
a: {
model: 'A'
},
c: {
model: 'C'
}
}
}
// Model C
{
attributes: {
as: {
collection: 'A',
via: 'cs',
through: 'b'
},
}
}