filtered list of strings property
const BookrackSchema = {
name: 'Bookrack',
properties: {
book_names:'string[]',
}
};
Bookrack1.book_names=['A','B','C'];
Bookrack2.book_names=['B','C','D'];
Bookrack3.book_names=['C','D','E'];
a:realm.objects('Bookrack').filtered(`ANY book_names = $0 `,'B');
b:realm.objects('Bookrack').filtered(`book_names CONTAINS $0 `,'B');
get Bookrack1 And Bookrack2
a.The keypath following 'ANY' or 'SOME' must contain a list
b.Object type 'Table' not supported
It is currently not supported to query list of strings, only list of objects can be queried.
@kneth
It is currently not supported to query list of strings, only list of objects can be queried.
I think I have the same problem. Please, could you show me a workaround? Link to Stackoverflow
It is very important for me. I could donate a little money to you.
You can store the string values in a proxy object:
const StringValueSchema = {
name: 'StringValue',
properties: {
value:'string',
}
};
const BookrackSchema = {
name: 'Bookrack',
properties: {
book_names:'StringValue[]',
}
};
Then you can query like:
realm.objects('Bookrack').filtered(`ANY book_names.value = $0 `,'B');
@nirinchev
First, thank you so much for your response. I tried your example and i used the following for initializing:
realm.write(() => {
realm.create("Cars", {
name: "Honda",
category: "compact",
image: global.base64_images.honda,
specifications: ["test"],
})
Now it returns me an error "Error: JS value must be of type "object", got (test).
for specifications i need a list of strings like: ["automatic,"suv","green"]. Excuse me.. do i miss something stupid?
That is correct - because we're faking a list of strings, you'll need to wrap them in objects:
realm.write(() => {
realm.create("Cars", {
name: "Honda",
category: "compact",
image: global.base64_images.honda,
specifications: ["test"].map((str) => {
return realm.create("StringValue", {
value: str
});
}),
});
Similarly, if you want to get a list of strings from the collection, you'll need a reverse map:
const strings = car.specifications.map((s) => s.value);
@kneth I want ask that it is not supported to query list of strings, how about int or double? just strings?
@mingxin-yang Querying lists of primitive types (string, int, etc.) is still an open issue: https://github.com/realm/realm-object-store/issues/513
I hope that we can make some progress in the fall but I can't give you an ETA.
Hi I am also interested in the progress of this implementation
I think it's very necessary. At least, it should be explained that there is not support for query in list of primitive properties. I've already created a my db expecting that I could to such type of queries.
Also it would avoid to create a new class for each field when is as simple as a string or number.
Now I've got 2 options either change to a single string with a separator (no fun of this one) or create a class for each field (it adds more complexity to maintain the db)
This is in progress now in realm-core.
➤ Brian Munkholm commented:
[~kenneth.geisshirt]Â I assume this is done now and can be closed?
Realm Core has implemented comparison operators for array of primitive types, and it has been released in Realm JavaScript v10.0.0-beta.1. I suggest that you try out the latest beta (v10.0.0-beta.7).
Most helpful comment
It is currently not supported to query list of strings, only list of objects can be queried.