Flexible-Sync and relationships

Hi there,
i’m experiencing with flexiblke sync and i try to undestend how relationships works.
Consider this two schema:

Facility is the table in which are collected some facilities and they can be of different types, so i make a relationship with Facility and Types

Facility schema and relationship with Type

{
  "_facId": {
    "ref": "#/relationship/mongodb-atlas/facilities/Types",
    "foreignKey": "_id",
    "isList": false
  }
}

{
  "title": "Facility",
  "bsonType": "object",
  "required": [
    "owner_id",
    "_facId"
  ],
  "properties": {
    "_id": {
      "bsonType": "objectId"
    },
    "_facId": {
      "bsonType": "long"
    },
    "owner_id": {
      "bsonType": "long"
    },
    "facName": {
      "bsonType": "string"
    },
    "facDescrizione": {
      "bsonType": "string"
    },
    "type": {
      "bsonType": "long"
    }
  }
}

Type Schema

{
  "title": "Type",
  "bsonType": "object",
  "required": [
    "_id",
    "nome"
  ],
  "properties": {
    "_id": {
      "bsonType": "long"
    },
    "tipo": {
      "bsonType": "string"
    },
    "descrizione": {
      "bsonType": "string"
    },
    "nome": {
      "bsonType": "string"
    }
  }
}

And here is the first thing i didn’t undestand: from the manual a read that

To-one relationships must be optional

When you declare a to-one relationship in your object model, it must be an optional property. If you try to make a to-one relationship required, Realm throws an exception at runtime.

But if i take out _facId from required i got this error on UI inteface
failed to get queryable fields by table: field "_facId" in table "Facility" is not an allowed queryable field: queryable field cannot be a cross-collection link

So i made that field as required.

Client side (Java SDK) i use this subscritpion that works fine without relationships

Subscription subscription = realm.getSubscriptions().find(realm.where(Facility.class)
                                        .equalTo("owner_id", 0));

but i got this error:

E/REALM_JAVA: Session Error[wss://realm.mongodb.com/]: BAD_QUERY(realm::sync::ProtocolError:226): Invalid query (IDENT, QUERY): failed to parse query: query contains table not in schema: “Facility” Logs: xxxxxxxxxxxxx

Where do i mistake?
Thank you in advance

Hi, so you have run into 2 different issues.

The first, is that as the first message you posted states, we do not support syncing on a query on a link field. So initially you had your schema defined properly and so we reject the query when we receive it from the server. I’m happy to say we are actually lifting this limitation in our next release (1 week), so you will be able to sync on a link field.

The second issue you run into is that you are defining an “invalid” schema by making the properly required.

In terms of moving forward, it might be best to wait a week. We will deploy the ability to sync on a link field on this coming Wednessday

Thanks,
Tyler

Thank you,
I’ll wait then :wink:

This topic was automatically closed 5 days after the last reply. New replies are no longer allowed.