Reputation: 65
I'm developing an application using Hyperledger composer and its related part of the model file as bellows.
abstract participant Stakeholder {
o String name
o Address address
o String email optional
o String telephone optional
o Certification certification optional
o String[] images optional
o Company company
o String username
o String password
}
participant Farmer identified by stakeholderId extends Stakeholder {
o String stakeholderId
o String description optional
--> Farm[] farms
}
I'm trying to retrieve specific farmers by their username using below query.
query getUserFromUsername{
description:"get user from username"
statement:
SELECT org.ucsc.agriblockchain.Stakeholder
WHERE (username == _$username)
}
But it does not work as expected. Here, since Farmer is not the only stakeholder in the system, the Stakeholder abstract participant is used.
Any suggestions?
Upvotes: 0
Views: 184
Reputation: 3426
You can move the identified by stakeholderId to the abstract participation as mentioned below.
abstract participant Stakeholder identified by stakeholderId{
o String stakeholderId
o String name
o Address address
o String email optional
o String telephone optional
o Certification certification optional
o String[] images optional
o Company company
o String username
o String password
}
participant Farmer extends Stakeholder {
o String description optional
--> Farm[] farms
}
To query for getUserFromUsername
query getUserFromUsername{
description:"get user from username"
statement:
SELECT org.ucsc.agriblockchain.Farmer
WHERE (username == _$username)
}
Upvotes: 1
Reputation: 5570
Because it is an abstract type, there is no data for the "Stakeholder" registry. You need to query the Farmer registry ... SELECT org.ucsc.agriblockchain.Farmer ...
Changing Stakeholkder from abstract to concrete won't help either if Farmer extends it because the Farmer will still be part of the Farmer registry.
I'm not sure exactly what you are wanting to achieve from the model, but you could revert to a single Participant type with optional fields for the different Stakeholder types, otherwise just write separate queries for the different Participant Types, and collate the results yourself in your code.
Update Following Comment
That Query against the Farmer registry should work.
Couple of hints ...
(If you still have problems, please post the whole model, the latest query, and some example data that you are using in JSON format.)
Upvotes: 1