Connect two tables Realm & React Native

Viewed 37

I need to somehow connect two tables together. They are 1:n (1 City can have multiple Events, but one Event can have only one city). I tried to look it up, but I still don't fully understand it, so Ive decided to ask StackOverflow community.

This is my schema and Realm.open code.

const CitySchema = {
  name: "Town",
  properties: {
    _id: "int",       // 1
    name: "string",   // Obec Jalubí
    region: "string", // Zlínský kraj
    street: "string", // Jalub 1
    city: "string",   // 123 45 Jalubí
    phone: "int",     // 999 999 999
    ico: "int",       // 123456789
    dic: "string",    // CZ123456789
    logo: "string",   // https://www.jalubi.eu/skins/jalubi.eu_lego2/images/crest.png
    lat: "double",    // float  50.1163
    lng: "double"     // float  18.4279
  },
  primaryKey: "_id",
};

const EventSchema = {
  name: "Detail",
  properties: {
    _id: "int",       // 1
    city_id: "int",   //1
    eventName: "string",   // Balloon popping
    eventDescription: "string", // This event is about....
  },
  primaryKey: "_id",
};

(async () => {

  const realm = await Realm.open({
    path: "myrealm",
    schema: [CitySchema, EventSchema],
  });
})();
0 Answers
Related