From 32212ab79c3579325e173f25e6dcd465bed582a0 Mon Sep 17 00:00:00 2001 From: heavensoft Date: Sat, 15 May 2021 04:53:30 +0800 Subject: [PATCH] update docs/uniCloud/clientdb.md. --- docs/uniCloud/clientdb.md | 18 +++++++++++++++++- 1 file changed, 17 insertions(+), 1 deletion(-) diff --git a/docs/uniCloud/clientdb.md b/docs/uniCloud/clientdb.md index a70124469..035c5965a 100644 --- a/docs/uniCloud/clientdb.md +++ b/docs/uniCloud/clientdb.md @@ -1425,7 +1425,7 @@ department部门表的schema中,将字段`parent_id`的"parentKey"设为"_id" parentKey字段将数据表不同记录的父子关系描述了出来。查询就可以直接写了。 -注意一个表内只能有一个父子关系,即一个表的schema里只能配置一份parentKey。 +注意:一个表的一次查询中只能有一个父子关系。如果一个表的schema里多个字段均设为了parentKey,那么需要在JQL中通过parentKey()方法指定某个要使用的parentKey字段。 schema里描述好后,查询就变的特别简单。 @@ -1636,6 +1636,22 @@ db.collection("department") } ``` + +**通过parentKey方法指定某个parentKey** + +如果表的schema中有多个字段都配置了parentKey,但查询时其实只能有一个字段的parentKey关系可以生效,那么此时就需要通过parentKey()方法来指定这次查询需要的哪个parentKey关系生效。 + +parentKey()方法的参数是字段名。 + +```js +db.collection('department') +.parentKey('parent_id') // 如果表schema只有一个字段设了parentKey,其实不需要指定。有多个字段被设parentKey才需要用这个方法指定 +.get({ + getTree: true + }) +``` + + **示例** 插件市场有一个 家谱 的示例,可以参阅:[https://ext.dcloud.net.cn/plugin?id=3798](https://ext.dcloud.net.cn/plugin?id=3798) -- GitLab