我有以下型号:
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}
为什么数组的附加值被识别为资源而不是关系?
如果我将模型更改为
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}
你提到添加这个:"rohstoff": [
"resource:org.xx.xx.Rohstoff#ROH_001",
"resource:org.ba.xx.Rohstoff#ROH_002"
]
那是通过CLI还是事务处理器?你能提供更多细节吗?
在事务处理器函数中,添加新关系可能需要factory.newRelationship(String ns, String type, String id)
方法。
见:https://ibm-blockchain.github.io/develop//api/common-factory#newrelationship
我也面临着类似的问题。我有这个:
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
}
希望它可以帮助某人。