PostgresQL Realm Data Adapter To-Many relationship without lists


#1

I am syncing a fairly complex PostresQL Database to Realm - My client will be given a LocationId which I can use to query this schema to get the access_permissions

  name: 'access_permission_locations',
  primaryKey: 'id',
  properties: {
    id: 'string',
    access_permission_id: 'access_permissions',
    location_id: 'string'
  }
};

I then have to travers a ‘access_permission_access_records’ Postgres join table to get what I require (access_records)

  name: 'access_permission_access_records',
  primaryKey: 'id',
  properties: {
    id: 'string',
    access_record_id: 'access_records',
    access_permission_id: 'access_permissions'
  }
}

I am Syncing from Postgres to Realm so using ‘Lists’ is not possible for this to-many relationship

I have seen in the docs (https://docs.realm.io/sync/backend-integration/postgres-connector#lists)
It says “If you don’t need ordered lists you can change your model to reference the parent object which means list properties are no longer needed”

How would I go about changing the model to reference the parent object?


#2

Store the parent in the child like this:

Model Parent {
     var id
     etc.
}
Model Child {
    var id
    var parent: Parent
    etc
}

#3

@freeubi

I have tried setting the “parent type” on the joint table like this

  name: 'access_permission_access_records',
  primaryKey: 'id',
  properties: {
    id: { type: 'string' },
    account_id: 'string',
    access_record_id: { type: 'access_records' },
    access_permission_id: { type: 'access_permissions' },
    parent: {
      type: 'access_permission_locations'
    }
  }
};

But my column in realm returns only null values
Could it be because my PostgresQL table is a Many to Many Join Table? Does the adapter support Parent Child types for this?