You need to enable JavaScript to run this app.
优惠活动
大模型
产品
解决方案
定价
更多

通过查询获取关系属性:按企业ID查询Request资产问题

如何查询关联Container所属Company的Request资产?

当然可以实现这个需求!你的原查询问题出在关联路径的语法上,咱们来一步步修正:

问题分析

先确认你的模型逻辑是通顺的:

  • Request资产关联到Container资产
  • Container资产通过owner字段关联到Company参与者

原查询里的container.owner.id写法不符合Hyperledger Composer的查询语法规范——因为owner本身就是Company的引用对象,在查询语句中不需要额外访问.id属性来做匹配。

正确的查询写法

直接通过引用对象和目标ID参数比较即可,修改后的查询如下:

query getRequestsByCompany {
  description: "Get requests by company"
  statement: SELECT org.acme.shipping.assets.Request
              WHERE (container.owner == _$company_id)
}

为什么这样写?

在Hyperledger Composer的查询语法里有个便捷规则:

  • 当你用关联引用(比如container.owner)和字符串参数做比较时,Composer会自动把引用对象的标识符和参数值做匹配
  • 这里的_$company_id参数只需要传入Company参与者的ID字符串(比如COMP-001),不需要完整的资源路径(比如org.acme.shipping.participants.Company#COMP-001)

额外验证点

确保你的模型关联定义没问题:

  • Request里的container字段是正确的-> Container关联
  • Container里的owner字段是正确的-> Company关联

只要模型结构正确,这个查询就能正常返回所有关联Container属于指定Company的Request资产。

内容的提问来源于stack exchange,提问作者Lars

相关产品推荐
方舟 Agent Plan

超全模态模型 × Harness 升级,最新支持 Deepseek-V4.1-Flash、GLM-5.3 系列、Doubao-Seedream-5.0-pro、Kimi-K3 (部分), 限时 9.9 元起

最近更新时间:2026.05.28 06:29:14