Realm-js: Predicate expressions must compare a keypath and another keypath or a constant value

Created on 21 Aug 2017  路  4Comments  路  Source: realm/realm-js

class Message extends Realm.Object {}
Message.schema = {
name: "Message",
properties: {
id: "string",
messageId: "string",
text: "string",
time: "string",
type: "string"
}
};

getMessage(id) {
const messageId = id;
return realm.objects("Message").filtered("id=" + messageId);
}

if l use getMessage();
it will throw " Predicate expressions must compare a keypath and another keypath or a constant value" Exception

T-Help

Most helpful comment

@cl1069573062 Any indication of what messageID is?

You are missing quotes around messageId i.e., filtered('id = "' + messageID + '"');

All 4 comments

@cl1069573062 Any indication of what messageID is?

You are missing quotes around messageId i.e., filtered('id = "' + messageID + '"');

That'd probably be better written as filtered('id = $0', messageID) to avoid problems if the substituted value happens to contain double quote characters.

@bdash thanks that's work

Cool. I'll close the issue.

Was this page helpful?
0 / 5 - 0 ratings

Related issues

kontinuity picture kontinuity  路  3Comments

jmartindivmedianet picture jmartindivmedianet  路  3Comments

laznrbfe picture laznrbfe  路  3Comments

ashah888 picture ashah888  路  3Comments

texas697 picture texas697  路  3Comments