Sails.js gets a lot of links

I have a model (user) that has a connection with another model (phone). This association is to many many. The following call is built into Sails and allows me to get all the phone entries for a specific user:

GET - /user/:userId/phones 

I would like to be able to implement pagination on this call, but cannot figure out how to get the total number of results. I tried to rewrite the drawings find.js and / or findOne.js in order to return the score, but the above call does not seem to go through this logic.

+7
javascript
source share
1 answer

Great question. Sails implements many-to-many associations using the "join" model. It does not appear in the api / models folder, but you can request it if you need to. In your case, it will be something like:

 sails.models['user_phones__phone_users'].count({user_phones: userId}).exec(...) 

The exact model name depends on your models and their via keys; The easiest way to figure this out is to run the sails console and do:

 sails.util.keys(sails.models) 

to list all the models in the system.

+8
source share

All Articles