gpt4 book ai didi

javascript - RxDB 在另一个集合的对象数组中填充一个数组

转载 作者:搜寻专家 更新时间:2023-10-30 19:52:33 26 4
gpt4 key购买 nike

我正在尝试从另一个集合中填充一个 id 数组

我的 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 的文档我应该能够:

嵌套引用示例

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 属性已填充。

最佳答案

除非您使用 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());

关于javascript - RxDB 在另一个集合的对象数组中填充一个数组,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/52917378/

26 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com