【问题标题】:How can i merge two schemas我如何合并两个模式
【发布时间】:2021-06-29 13:08:24
【问题描述】:

我想在领域数据库中组合两个模式并对它们执行操作,就像在 sql 中加入一样。但我不知道该怎么做。我没有

列表项

了解文档中的任何内容。我该怎么做?我有两个原理图

const barkod = {
  name: 'barkod',
  properties: {
    StokNo: { type: 'int', indexed: true },
    Barkod: { type: 'string', indexed: true },
    Birim: 'string',
    BarkodTipi: 'string',
    Aciklama: 'string?',
    YStokNo: 'int'
  }
  // primaryKey: 'Barkod',
}

const stok = {
  name: 'stok',
  primaryKey: 'StokNo',
  properties: {
    StokNo: 'int',
    StokAdi: { type: 'string', indexed: true },
    StokKisaAdi: 'string',
    StokKodu: 'string',
    StokTanimi: 'string',
    GrupKodu: 'string',
    KdvOranP: { type: 'int', default: 0 },
    KDVOranT: { type: 'int', default: 0 },
    OzelKodu1: 'string',
    OzelKodu2: 'string',
    OzelKodu3: 'string'
  }
}`enter code here`
 and I want to join these two schemas
 
         
'SELECT Stok.StokAdi, Barkod, StokNo FROM ? AS Barkod JOIN ? AS Stok ON Barkod.StokNo = Stok.StokNo',

【问题讨论】:

  • 欢迎来到 SO。重要的是要清楚问题并包含您遇到困难的代码。连接不组合模式 - 连接是一种通过使用每个表共有的值来组合来自两个或多个表的字段的方法。为了让我们提供帮助,我们需要查看您的 Realm 模型并了解它们之间的关系以及您正在尝试做的事情。请花点时间查看How do I ask a good question?How to create a Minimal, Complete, and Verifiable example

标签: javascript react-native realm


【解决方案1】:

我找到了问题的解决方案。我就是这样做的。希望对遇到这个问题的人有所帮助。

 const CarSchema = {
    name: 'Car',
    properties: {
      make: 'string',
      model: 'string',
      miles: {type: 'int', default: 0},
    },
  };
  const PersonSchema = {
    name: 'Person',
    properties: {
      name: 'string',
      birthday: 'date',
      cars: 'Car[]',
      //   picture:  'data?' // optional property
    },
  };

  const exp1 = () => {
    var person;
    Realm.open({schema: [CarSchema, PersonSchema]})
      .then(realm => {
        realm.write(() => {
          person = realm.create('Person', {
            name: 'ayşegül',
            birthday: new Date(1995, 11, 25),
            //  cars: 'Car[]',
          });
          console.log(person.cars);
          let carList = person.cars;
          carList.push({make: 'Honda', model: 'model1', miles: 100});
          carList.push({make: 'Toyota', model: 'model2', miles: 200});
          console.log(person);
        });
      })
      .catch(error => {
        console.log(error);
      });
  };

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 2018-04-29
    • 2011-06-07
    • 2022-07-05
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多