I can't filter with a variable
rosostolato opened this issue · 5 comments
jinqu-odata version
v0.3.1
Steps to reproduce
query.createQuery(DomeFeature).expand('users', ['enable'], u => u.userMail === user.mail)
Expected behavior
expected query: ?$expand=users($filter=userMail eq email@email.com;$select=enable)
Actual behavior
actual query: ?$expand=users($filter=userMail eq user/mail;$select=enable)
Thanks for the feedback.
Because we have to stringify the function and parse the expression to convert it to query string parameters, scope is lost (not like c# expressions). To overcome this JavaScript limitation, jinqu supports scope parameters.
query.createQuery(DomeFeature).expand('users', ['enable'], u => u.userMail === user.mail, { user })
This way, user variable will be available when parsing expression.
HI, thank you for the support!
I tried it and still building the same query:
$expand=users($filter=userMail eq user/mail;$select=enable)
I searched on jinqu docs and found something like this:
const filtered = orders.where('c => c.id > value', { value: 3 })
So I tested with this code and it didn't work either:
query.createQuery(DomeFeature).expand('users', ['enable'], 'u => u.userMail === value', { value: user.mail })
I tried to debug inner functions and inside createExpandArgs
function, the scope is an array of array of object... maybe it can help you
This is what i'm talking about:
when the code finds name in s
, s is an array with indexes 0, 1, 2... not an object
The problem is somehow on createExpandArgs generated lib:
function createExpandArgs(nav, prm1, prm2) {
var scopes = [];
for (var _i = 3; _i < arguments.length; _i++) {
scopes[_i - 3] = arguments[_i]; // <--- creating arrary of array
}
var selector;
var filter;
if (typeof prm1 !== "function" && typeof prm1 !== "string") {
selector = prm1;
filter = prm2;
}
else {
filter = prm1;
scopes = prm2 ? __spread([prm2], scopes) : scopes;
}
return [jinqu_1.PartArgument.literal(nav), jinqu_1.PartArgument.literal(selector), jinqu_1.PartArgument.identifier(filter, scopes)];
}
I reproduced the issue, and will be working on it.
Jinqu is not resolving cascading properties for parameters, for now you can use it like this:
const mail = user.mail;
query
.createQuery(DomeFeature)
.expand('users', ['enable'], u => u.userMail === mail, {mail})
Fixed with 0.3.2 npm.
Thank you again for reporting.