Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix($elemMatch): fix $elemMatch for the given example in the github r… #12

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion query.js
Original file line number Diff line number Diff line change
Expand Up @@ -314,7 +314,7 @@
else if (constraint instanceof RegExp) return this.$regex(value, constraint)
else {
for (var key in constraint) {
if (!this[key]) return this.$eq(value, constraint, row, getter)
if (!this[key]) return this._satisfies(value[key], constraint[key], row, getter)
else if (!this[key](value, constraint[key], row, getter)) return false;
}
return true;
Expand Down
31 changes: 30 additions & 1 deletion test/elemMatch.js
Original file line number Diff line number Diff line change
Expand Up @@ -151,6 +151,35 @@ describe("Underscore Query Tests", function () {
}
});
assert.equal(result.length, 1);
})

var rows = [
{title: "Home", comments:[
{text:"I like this post"},
{text:"I love this post"},
{text:"I hate this post"}
]},
{title: "About", comments:[
{text:"I like this page"},
{text:"I love this page"},
{text:"I really like this page"}
]}
];
result = _.query(rows, {
comments: {
$elemMatch: {
text: "I really like this page"
}
}
});
assert.equal(result.length, 1);

result = _.query(rows, {
comments: {
$elemMatch: {
text: /really/i
}
}
});
assert.equal(result.length, 1);
})
})