2 / 2
Aug 2024

I’m trying to figure our how relationship work in realm, it should be very simple, and the documentation is great I still cannot figure out how to do it.

Conversation has many messages
Message belong to Conversation

Conversation.id <> Message.conversation

export type Conversation = { _id: Realm.BSON.ObjectId; name: string; participants: Realm.List<string>; phone_number: string; timestamp: number; }; export const ConversationSchema = { name: "Conversation", properties: { _id: "objectId", name: "string", participants: "string[]", phone_number: "string", timestamp: "double", }, primaryKey: "_id", }; export type Message = { _id: Realm.BSON.ObjectId; conversation: Conversation; media?: Message_media; message_id: string; recipient: string; statuses: Realm.List<Message_statuses>; text?: Message_text; timestamp: number; type: string; }; export const MessageSchema = { name: "Message", properties: { _id: "objectId", conversation: "Conversation", media: "Message_media", message_id: "string", recipient: "string", statuses: "Message_statuses[]", text: "Message_text", timestamp: "double", type: "string", }, primaryKey: "_id", };

Above not working.
Unsupported comparison between type ‘link’ and type ‘string’

How do I query conversation.message.length?

const conversations = useQuery<Conversation>( ConversationSchema.name, (collection) => collection, [requeryFlag] ); conversation[0].message // does not work

And when I query the conversation list:

const conversations = useQuery<Conversation>( ConversationSchema.name, )

I’m not allowed to do this.
data[0].linkingObjects("Message", "conversation")

DOCS ARE NOT ELABORATIVE