在Hyperledger Composer中查询

时间:2017-10-26 07:44:17

标签: hyperledger hyperledger-composer

当我尝试进行查询时:

query PapersFromAPoll
{
    description: "retrieve all the papers from a poll"
    statement:
         SELECT org.acme.democracity.Paper 
          WHERE(poll.pollId == _$id)
}

我无法获取任何行,这是我进行此查询的片段:

return query('PapersFromAPoll',{id : count.poll.pollId})

这很奇怪,因为当我擦除WHERE语句并且我在没有任何参数的情况下进行简单查询时,它完美地运行。

在model.cto文件中进行纸张和投票:

asset Paper identified by paperId {
    o String paperId
    o String[] fields
    --> Poll poll  //Paper related with a poll
}

asset Poll identified by pollId {
    o String pollId
    o Ask[] asks
}

1 个答案:

答案 0 :(得分:5)

query PapersFromAPoll
{
  description: "retrieve all the papers from a poll"
  statement:
    SELECT org.acme.democracity.Paper 
      WHERE(poll == _$pollId)
}

因此,您可以通过提供对该Poll资产的引用来按Poll资产进行过滤。当您尝试使用pollId进行查询时,它必须是对资源的引用resource:org.acme.democracity.Poll#{insert_id}