Reputation: 700
I'm trying to use the AngularJS SDK of Loopback but i didn't find a way to do a request with multiple where clause (and there are no examples in the documentation).
$scope.events = Professional.events({
id: '1',
filter: {
where: {
EndDate: {gt: new Date("2017-05-20T00:00:00.000Z")}
}
}
},
function(err) {
[...]
});
This example perfectly works but I want to do this:
$scope.events = Professional.events({
id: '1',
filter: {
where: {
and: {
EndDate: {gt: new Date("2017-05-20T00:00:00.000Z")},
EndDate: {it: new Date("2017-06-20T00:00:00.000Z")}
}
}
}
},
function(err) {
[...]
});
The error displayed in the terminal
Error: The and operator has invalid clauses {"EndDate":{"it":"2017-06-20T00:00:00.000Z"}}: Value is not an array or object with sequential numeric indices
Another try:
$scope.events = Professional.events({
id: '1',
filter: {
where: {
EndDate: {gt: new Date("2017-05-20T00:00:00.000Z")},
EndDate: {it: new Date("2017-06-20T00:00:00.000Z")}
}
}
},
function(err) {
[...]
});
The exact same error code is displayed. Any idea ?
EDIT: This solution doesn't work
$scope.events = Professional.events({
id: '1',
filter: {
where: {
and: [
{EndDate: {gt: new Date("2017-05-20T00:00:00.000Z")} },
{EndDate: {it: new Date("2017-06-20T00:00:00.000Z")} }
]
}
}
}
,
function(err) {
[...]
});
The code error (500 http)
Erreur non traitée pour la demande GET /api/Professionals/1/events?filter=%7B%22where%22:%7B%22and%22:%5B%7B%22EndDate%22:%7B%22gt%22:%222017-05-20T00:00:00.000Z%22%7D%7D,%7B%22EndDate%22:%7B%22it%22:%222017-06-20T00:00:00.000Z%22%7D%7D%5D%7D%7D : Error: Date non valide : [object Object]
Upvotes: 2
Views: 2507
Reputation: 5719
If you are trying to compare multiple conditions with and
you have to pass an array to and like this:
where:
{
and: [
{title: 'My title'},
{content: 'Hello'}
]
}
The above code means give me all data where title is 'My title' and content is 'Hello'.
In your case it would be:
where: {
and: [
{ EndDate: {gt: new Date("2017-05-20T00:00:00.000Z")} },
{ EndDate: {it: new Date("2017-06-20T00:00:00.000Z")} }
]
}
Upvotes: 3