Hyperledger fabric 在Hyperledger Composer中使用关系进行查询
我在Hyperledger Composer中进行了一个查询,其中在查询中尝试搜索借款人的所有发票。借款人是发票资产的参与者:Hyperledger fabric 在Hyperledger Composer中使用关系进行查询,hyperledger-fabric,hyperledger,hyperledger-composer,Hyperledger Fabric,Hyperledger,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 Doubl
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 composer中通过以下编码实现了这一点:
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子句的重复查询,然后检查返回的数据以帮助理解用于查询的参数
(通过使用参与者,我认为您的资产将包括首次使用资产类型时模型中的第一个参与者类型-这听起来可能会产生一些意外行为,因此指定实际参与者类型是有意义的。)