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,400 points
1,399 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,090 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
2,672 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,100 points
3,613 views
0 votes
1 answer

Hyperledger Sawtooth vs Quorum in concurrency and speed Ask

Summary: Both should provide similar reliability of ...READ MORE

answered Sep 26, 2018 in IoT (Internet of Things) by Upasana
• 8,620 points
1,461 views
+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,740 points
1,024 views
0 votes
1 answer
0 votes
1 answer
webinar REGISTER FOR FREE WEBINAR X
REGISTER NOW
webinar_success Thank you for registering Join Edureka Meetup community for 100+ Free Webinars each month JOIN MEETUP GROUP