如何向阵列添加关系并更新资产?

时间:2018-03-10 16:52:17

标签: hyperledger-composer

我有以下型号:

 transaction ProduceHalbfabrikat {
   o String halbfabrikatId
    --> Rohstoff[] rohstoff    
}

交易看起来像:

return getAssetRegistry(NS + '.Halbfabrikat')
            .then(function (halbfabrikatRegistry) {
               return halbfabrikatRegistry.get(halbfabrikatId);
                })
                // get the asset
                .then(function(halbfabrikatRegistry){
                    halbfabrikatRegistry.rohstoff.push(rohstoff);
                    console.log("Halbfabrikat after PUSH = " + halbfabrikatRegistry.rohstoff);
                        // get the asset again to update the Halbfabrikat 
                        return getAssetRegistry(NS + '.Halbfabrikat')
                        .then(function(updateHalbfabrikatRegistry){
                            // Update the asset
                            return updateHalbfabrikatRegistry.updateAll([halbfabrikatRegistry]);
                        });

现在,如果我尝试将新的“rohstoff”添加到halbfabrikatRegistry.rohstoff数组中:

"rohstoff": [
      "resource:org.xx.xx.Rohstoff#ROH_001",
      "resource:org.ba.xx.Rohstoff#ROH_002"
    ]

我收到以下错误:

t: Model violation in instance org.xx.xx.Halbfabrikat#111 class org.xx.xx.Rohstoff has value Resource {id=org.xx.xx.Rohstoff#ROH_001},Resource {id=org.xx.xx.Rohstoff#ROH_002} expected a Relationship.
在console.log中的

我可以看到我想要添加的关系是资源:

Halbfabrikat after PUSH = Relationship {id=org.xx.xx.Rohstoff#ROH_001},Resource {id=org.xx.xx.Rohstoff#ROH_002},Resource {id=org.xx.xx.Rohstoff#ROH_003}

为什么数组的附加值被识别为Ressource而不是关系?

如果我将模型更改为

transaction ProduceHalbfabrikat {
   o String halbfabrikatId
    --> Rohstoff rohstoff    
}

并逐个添加关系,它有效: 控制台日志:

Halbfabrikat after PUSH = Relationship {id=org.xx.xx.Rohstoff#ROH_001},Relationship {id=org.xx.xx.Rohstoff#ROH_001}

2 个答案:

答案 0 :(得分:0)

您提到添加此内容: timeStyle

是通过CLI还是事务处理器?你能提供更多细节吗?

在事务处理器功能中,添加新关系可能需要"rohstoff": [ "resource:org.xx.xx.Rohstoff#ROH_001", "resource:org.ba.xx.Rohstoff#ROH_002" ]方法。

请参阅:https://ibm-blockchain.github.io/develop//api/common-factory#newrelationship

答案 1 :(得分:0)

我也面临着类似的问题。我有这个:

asset Document identified by documentId {
  o String documentId
  o String docName
  o String documentDescription
  o String docStatus
  o String docAIApprovalStatus
  o String docFinalApproval
  o String docPath
  o String originalname
  o String mimetype
  o Integer size
  --> Member owner
}

@returns(String)
transaction AddDocumentTransaction{
  --> Document document
}

所以在客户端,我正在构造Document对象并将其提交给事务。因此,我面临类似的错误:

{ ValidationException: Model violation in instance org.ibm.dms.AddDocumentTransaction#7d9d5e5237c89b990b69b388a1101cbef99014d285ffcef8deb138fe822a3e75 class org.ibm.dms.Document has value Resource {id=org.ibm.dms.Document#aa781c10-5b6a-11e9-a6b6-4d34f343ceb1} expected a Relationship.

相反,我将Document对象的所有核心值传递给了事务,然后在事务处理器功能中构造了Document对象。比我没有面对这个问题。现在我的代码如下:

@returns(String)
transaction AddDocumentTransaction{
  o String documentId
  o String docName
  o String documentDescription
  o String docStatus
  o String docAIApprovalStatus
  o String docFinalApproval
  o String docPath
  o String originalname
  o String mimetype
  o Integer size
  o String owneraccnum
}

希望它可能对某人有所帮助。