How do I create a relationship between list of suppliers and a single order in Hyperledger Composer

+1 vote

I have a transaction OrderPlace which takes list of supplier as input and creates an order.

transaction OrderPlace 

    {
        o String orderId
        --> Consumer consume
        o OrderDetails details
        --> Supplier[] supply
        --> Commodity com1
    }

The order is an asset having list of suppliers

asset Order identified by orderId {
    o String orderId
    o String orderName optional
    o OrderState state
    o OrderDetails details
    --> SupplyOrder[] OrderSupply
    --> Trader owner 
    --> Commodity com1
    --> Consumer consume
    --> Supplier[] supplier1
    o Rating rating optional
}

This order is created when OrderPlaced transaction is called and that should create relationship between the list of suppliers.

I was trying the code below for a single supplier

order.supplier = factory.newRelationship(namespace, 'Supplier', OrderPlaced.supplier.getIdentifier());
Mar 28, 2018 in Blockchain by Shashank
• 10,350 points
317 views

1 answer to this question.

+1 vote
Best answer
  1. Is your transaction actually called 'OrderPlaced' (in your code) ?? In your code this order is created when placeOrder transaction is called.

  2. Also, because you've defined an array of relationships to Supplier, the `factory' statement should probably be:

 order.supplier = factory.newRelationship(namespace, 'Supplier', placedOrder.supplier[0].getIdentifier());
answered Mar 28, 2018 by Johnathon
• 9,080 points

selected Aug 3, 2018 by Omkar

Related Questions In Blockchain

+4 votes
2 answers

How do I create a new block in Hyperledger Fabric?

This link might help you: https://github.com/hyperledger/fabric-sample ...READ MORE

answered Oct 11, 2018 in Blockchain by Sahu
490 views
0 votes
1 answer

How do I send back ethers to the sender of the tokens in a smart contract?

Whenever a smart contract receives ether via ...READ MORE

answered May 30, 2018 in Blockchain by Perry
• 17,020 points
414 views
0 votes
1 answer
+1 vote
1 answer
0 votes
1 answer

Invalid Batch or signature in Savtooth

This will solve your problem import org.apache.commons.codec.binary.Hex; Transaction txn ...READ MORE

answered Aug 1, 2018 in Blockchain by digger
• 26,550 points
77 views
0 votes
1 answer
0 votes
1 answer