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?