2
votes

I'm using sailjs + waterline, how to filtering data after populate models? here i try my code and doesn't work :

Approductbranch
    .find({deleted:1})
    .populate("mproduct_id",{where:{deleted:1}})
    .paginate({page:currpage,limit:utils.RowPerPage})
    .exec(callback)

in my code above, i want to execute sql like this :

select * from approductbranch a
inner join mproduct a
on a.id = a.mproduct_id
where a.deleted = 1
and b.deleted = 1

how to do this? thank! :)

3
The sails.js gitter room is also a good place to chat and get support: gitter.im/balderdashy/sails - Travis Webb

3 Answers

1
votes

Good question.

There currently isn't a way to do this directly, but there is an outstanding feature request in the Waterline repository that you can share your thoughts in.

1
votes

I think you can do like this:

Approductbranch
.find({deleted:1})
.populate("mproduct_id",{deleted:1, skip:currpage * utils.RowPerPage, limit:utils.RowPerPage})
.exec(callback)

it will be OK!

0
votes

You can filter a set of values before you populate. This is more performant since you're not getting more values than you need: https://github.com/balderdashy/sails-docs/blob/master/reference/waterline/queries/populate.md