Error in Flexible Sync: Unsupported Query for Nested Properties ('company.id') When Subscribing to Posts"

I’m trying to sync only the post belonging to the current user’s company during login at initial subscriptions.

class User : RealmObject {
@PrimaryKey
var id: ObjectId = ObjectId()
var name: String = “”
var email: String = “”
var company: Company? = null
}

class Company : RealmObject {
@PrimaryKey
var id: ObjectId = ObjectId()
var name: String = “”
var users: RealmList = realmListOf()
var posts: RealmList = realmListOf()
}

class Post : RealmObject {
@PrimaryKey
var id: ObjectId = ObjectId()
var title: String = “”
var content: String = “”
var author: User? = null
var company: Company? = null
}

I attempt to subscribe to posts of current company using the following code:

fun subscribeToPostData(companyId: ObjectId) {
// Posts belonging to the company
subs.add(
realm.query<Post>(“company.id == $0”, companyId),
“posts_for_company”,
updateExisting = true
)
}

Invalid query: unsupported query for table “Post”: invalid property: only simple top-level properties are supported in server-side queries.

How can I adjust my schema or query to fetch posts belonging to the current user’s company without encountering this error?

This is likely because Company is a link from post. One way to resolve this is to store companyID as a top-level field on the Post (alongside Company if you need that too).
Then, you can change your query to be companyID == $0