balderdashy / waterline-docs

WARNING: The content in this repo is out of date! See https://github.com/balderdashy/sails-docs for the most up-to-date documentation
452 stars 161 forks source link

Can I groupBy, sum, sort, limit, and populate? #111

Closed spacesuitdiver closed 8 years ago

spacesuitdiver commented 8 years ago

I've search a bit around the web and I can't seem to determine the proper way to do this (MySQL adapter):

Model.find({ app: appId })
.groupBy('user')
.sum('points')
.limit(10)
.sort({ points: 'desc' })
.populate('user')
.then(results => res.ok(results))

Works with query though I'm not sure how to populate from here:

Model
.query('SELECT SUM(points) as points, user FROM table GROUP BY user ORDER BY points desc LIMIT 10', 
    (err, results) => {
        if (err) return res.negotiate(err)
        res.ok(results)
    }
);
spacesuitdiver commented 8 years ago

Whoops didn't realize I was in -docs... Moving this discussion here here.