如何在响应composer-rest-server中包含关系对象?

时间:2017-06-15 05:42:22

标签: hyperledger-composer

我们已将Asset定义为:

asset PurchaseOrder identified by orderId {
  o String orderId
    --> SupplierChainParticipant createdBy
    --> SupplierChainParticipant assignedTo
  o String description    
  o String status
  o Integer quantity
  o String assetId    
}

Participant as:

participant SupplierChainParticipant  identified by participantId {
  o String participantId
  o String identity
  o String type     
}

现在,当我使用composer-rest-server的REST API获取Asset详细信息时,我会收到以下响应:

{
  "orderId": "o5",
  "createdBy": "resource:com.supplychain-network.SupplierChainParticipant#p1",
  "assignedTo": "resource:com.supplychain-network.SupplierChainParticipant#p2",
  "description": "New Engine",
  "status": "created",
  "quantity": 1,
  "assetId": "a1"
}

目前仅在获取participantId详细信息时才返回Asset,是否有办法获取参与者的详细信息以及Asset作为JSON响应?

2 个答案:

答案 0 :(得分:3)

如果您指定名为resolve的过滤器密钥并将值设置为not exists,则会解析关系,并且还会返回相关资产。

答案 1 :(得分:1)

通过示例改善接受的答案-

1. 'http://localhost:3000/api/PurchaseOrder?filter={"where":{"orderId":"A01"},"include":"resolve"}'

2. 'http://localhost:3000/api/PurchaseOrder?filter={"include":"resolve"}'