首页 > 解决方案 > Define unique relationships in hyperledger composer

问题描述

I have this simplified scenario:

asset device identified by deviceID
{
    o String deviceID
    o Data reading
}

concept Data identified by readingID
{
    o String ReadingID
    o Double Lng
    o Double Lat
}

Is it possible to avoid that different devices have the same reading associated, like a unique relationship? An example:

deviceID = 1111 --> readingID = aaaa

deviceID = 2222 --> readingID = aaaa

I am trying to avoid this situation. I tryied to use a relationship using:

asset device identified by deviceID
{
    o String deviceID
    --> Data reading
}

taking Data as an Asset, but I have the same problem.

标签: hyperledgerhyperledger-composer

解决方案


首先你的模型是:

asset device identified by deviceID
{
    o String deviceID
    o Data reading
}

concept Data 
{
    o String readingID
    o Double Lng
    o Double Lat
}

其次,Composer 中的关系不用于像 RDBMS 那样“强制”唯一性(因为它不使用 RDBMS,它使用键/值存储)。

检查您的设备资产是否尝试使用已与资产关联的 readingID(存储在概念中,隐藏在资产注册表中的资产中)的最简单方法是在注册表上运行查询并使用 true 或 false您的交易代码。除非您将已使用的 ID 作为注册表存储在其他地方,但会增加更多维护等。


推荐阅读