You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Hello,
I'm trying to get all Person with specific hobbyIds, but it seems like $in is not working for array fields. Is there any other option that I can use to query for people with specific hobbyIds?
var odm = jsonOdm;
odm.addSource("people",{
"Person" : [
{"id":1,"name":"Richi",jobId:8,hobbyIds:[1]},
{"id":2,"name":"Dave",jobId:2,hobbyIds:[2,4]},
{"id":3,"name":"Tom",jobId:3,hobbyIds:[3,5]},
{"id":4,"name":"Lisa",jobId:4,hobbyIds:[1,2,3]},
{"id":5,"name":"Hanni",jobId:3,hobbyIds:[1,5]},
{"id":6,"name":"Selma",jobId:8,hobbyIds:[1,4]},
{"id":7,"name":"Ralf",jobId:1,hobbyIds:[4,3]}
],
"Jobs" : [
{"id":8,"name":"plumber"},
{"id":2,"name":"programmer"},
{"id":3,"name":"chef"},
{"id":4,"name":"hairdresser"}
],
"Hobbies" : [
{"id":1,"name":"swimming"},
{"id":2,"name":"cycling"},
{"id":3,"name":"fishing"},
{"id":4,"name":"coding"},
{"id":5,"name":"dancing"}
]
},true);
// instantiate a collection object
var people = new odm.Collection('Person');
people.$hasOne("jobId","id","Jobs","job");
people.$hasMany("hobbyIds","id","Hobbies","hobbies");
var hairdresser = people.$query()
.$branch("hobbyIds").$in([1])
.$all();
console.log(hairdresser);
The code returns an empty array.
The text was updated successfully, but these errors were encountered:
@dmaziarz It doesn't work because $hasMany creates an array of arrays. $hasOne just creates an array. So $in compares
1===[1]
which failes. The last time I took a deeper look into the code was some years ago. It might take some time to check wether this is a bug or if this is correct behaviour.
Hello,
I'm trying to get all Person with specific hobbyIds, but it seems like $in is not working for array fields. Is there any other option that I can use to query for people with specific hobbyIds?
The code returns an empty array.
The text was updated successfully, but these errors were encountered: