Vishal
Vishal

Reputation: 55

I want to create a relationship between list of suppliers and a single order in Hyperledger Composer

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

transaction PlaceOrder 

    {
        o String orderId
        --> Consumer consumer
        o OrderDetails orderDetails
        --> Supplier[] supplier
        --> Commodity commodity
    }

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 orderDetails
    --> SupplyOrder[] supplyOrder
    --> Trader owner 
    --> Commodity commodity
    --> Consumer consumer
    --> Supplier[] supplier
    o Rating rating optional
}

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

For a single supplier I was using

order.supplier = factory.newRelationship(namespace, 'Supplier', placedOrder.supplier.getIdentifier());

but the above code is failing for list of suppliers.

Upvotes: 0

Views: 135

Answers (1)

Paul O'Mahony
Paul O'Mahony

Reputation: 6740

two things may help

  1. Is your transaction actually called 'placedOrder' (in your code) when you wrote "This order is created when placeOrder transaction is called " (just to check, it may well be).

  2. 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());

Upvotes: 1

Related Questions