Skip to content Skip to sidebar Skip to footer

How To Get A Model By Array Params From A Collection

I have a model like this: model = from: 'a@b.com' id: 1 to: [c@d.com] and I have a collection containing these kind of models. The collection needs to filter by from.

Solution 1:

At that point you need to use _.filter. If you look at the source code you can see that _.where is just a helpful wrapper around _.filter. _.where is good for simple filtering based on primitive comparison, but anything more complex you will have to write yourself.

# Filter for messages that contain the target address.
matchedTo = _.filter msgs, (msg) -> _.contains msg.to, login

# Pluck as usual
toIds = _.pluck matchedTo, 'msgId'

Post a Comment for "How To Get A Model By Array Params From A Collection"