RxDB заполняет массив в массиве объектов из другой коллекции - PullRequest
0 голосов
/ 21 октября 2018

Я пытаюсь заполнить массив идентификаторов из другой коллекции

Моя JsonSchema выглядит так:

{
  version: 0,
  type: "object",
  properties: {
    id: {
      type: "string",
      primary: true
    },
    // This is populated as expected
    working: {
      type: "array",
      ref: "othercollection",
      items: {
        type: "string"
      }
    },
    // This is where I am having problems
    notWorking: {
      type: "array",
      items: {
        type: "object",
        properties: {
          // This property is not being populated
          problem: {
            type: "array",
            ref: "yetanothercollection",
            items: {
              type: "string"
            }
          }
        }
      }
    }
  }
}

Из документов на https://pubkey.github.io/rxdb/population.html Я должен быть в состоянииto:

Пример с вложенной ссылкой

const myCollection = await myDatabase.collection({
  name: 'human',
  schema: {
    version: 0,
    type: 'object',
    properties: {
      name: {
        type: 'string'
      },
      family: {
        type: 'object',
        properties: {
          mother: {
            type: 'string',
            ref: 'human'
          }
        }
      }
    }
  }
});

const mother = await myDocument.family.mother_;
console.dir(mother); //> RxDocument

Пример с массивом

const myCollection = await myDatabase.collection({
  name: 'human',
  schema: {
    version: 0,
    type: 'object',
    properties: {
      name: {
        type: 'string'
      },
      friends: {
        type: 'array',
        ref: 'human',
        items: {
            type: 'string'
        }
      }
    }
  }
});

//[insert other humans here]

await myCollection.insert({
  name: 'Alice',
  friends: [
    'Bob',
    'Carol',
    'Dave'
  ]
});

const doc = await humansCollection.findOne('Alice').exec();
const friends = await myDocument.friends_;
console.dir(friends); //> Array.<RxDocument>

Поэтому мой вопрос: почему я не могу получить доступ к myDocument.notWorking[0].problem_?

Вот снимок экрана консоли, который может дать вам лучшее понимание моей ситуации:

Screenshot of console

Как вы можете видеть свойство ingredientsне заполнены данными из коллекции ингредиентов (не на рисунке).Однако свойство taxes заполняется.

1 Ответ

0 голосов
/ 26 августа 2019

Это невозможно, если вы не используете методы OEM.

https://rxdb.info/orm.html

const heroes = await myDatabase.collection({
  name: 'heroes',
  schema: mySchema,
  methods: {
    whoAmI: function(otherId){
        // Return the item with id `otherId` from the other collection here
        return 'I am ' + this.name + '!!';
    }
  }
});
await heroes.insert({
  name: 'Skeletor'
});
const doc = await heroes.findOne().exec();
console.log(doc.whoAmI());

Добро пожаловать на сайт PullRequest, где вы можете задавать вопросы и получать ответы от других членов сообщества.
...