hyperledger-fabric - 在 Hyperledger Composer 中使用关系进行查询
问题描述
我在 Hyperledger Composer 中进行了查询,在该查询中尝试搜索借款人的所有发票。借款人是发票资产的参与者:
asset Invoice identified by invoiceId {
o String invoiceId
o String invoiceRef optional
o DateTime dateCreated
o String type
o DateTime invoiceOrPurchaseDate optional
o Double amount
o DateTime invoiceDueDate optional
o String paymentStatus optional
o Boolean overdue
o Double outstandingBalance
--> Participant borrower
--> Participant lender
}
我需要一个查询来返回借款人的所有发票,我在 Hyperledger 作曲家中通过以下编码做到了这一点:
query QInvoiceByBorrower {
description: "Select invoice by borrower"
statement:
SELECT org.n.blockchaindemo.Invoice
WHERE (_$borrower == borrower)
}
但是当我尝试通过 REST API 调用查询时,我得到 [] 空结果如下:
http://10.10.4.244:3000/api/queries/QInvoiceByBorrower?borrower=resource:org.n.blockchaindemo.User#1381991
我可以知道如何在 Hyperledger Composer 中创建一个将使用外部关系进行搜索的查询吗?
解决方案
在您的发票定义中,您需要参考您的特定参与者类型,即用户而不是系统类型参与者。因此,发票的最后一部分将是:
o Double outstandingBalance
--> User borrower
--> User lender
}
通过此更改,您的查询应该可以工作。一个有用的诊断方法是创建一个不带where子句的重复查询,然后检查返回的数据以帮助了解用于查询的参数。
(通过使用 Participant,我认为您的资产将在首次使用资产类型时包含模型中的第一个参与者类型 - 这听起来可能会产生一些意想不到的行为,因此指定实际的参与者类型是有意义的。)
推荐阅读
- javascript - Handllebar 助手返回 href 的附加窗口 url 路径
- typescript - 如何在带有 Typescript 项目的 React Native 中使用 AWS Amplify?
- unity3d - unity2D多精灵问题(精灵编辑器问题)
- sqlite - Sqlite ROW_NUMBER 在 react-native-sqlite-storage 中不起作用
- java - 如何编写 MainActivity 和 ResultActivity 来添加两个数字?
- python - 如何在python中打印嵌套的JSON数据
- jenkins - 通过詹金斯管道传递给下游项目的参数化构建
- java - Java - 从请求 JSON 生成 JWS/JWT
- javascript - 在 ReactJS 中单击按钮时执行验证
- javascript - Vue 观察者数据未正确更新