3

I have been creating a model where one of my assets have a reference to a specific participant.

When I retrieve my asset using the composer-client API I would like to retrieve the details of the participant being referenced.

In the CTO language document I saw this sentence: "Relationships must be resolved to retrieve an instance of the object being referenced. The act of resolution may result in null, if the object no longer exists or the information in the relationship is invalid." but it does not describe how to do it.

Can someone please let me know what is the best way to resolve a relationship so that I can retrieve the instance of the object (in this case a participant) that I am pointing to?

1 Answers1

8

You can resolve relationships a couple of ways

Lets say we have an asset Widget that is defined as:

namespace SO

participant Person identified by email {
    o String email
}

asset Widget identified by assetId {
    o String email
    --> Person owner
}
  1. Once you have a Widget asset, you can call Widget.owner.getFullyQualifiedType() which returns the name of the participant registry the owner is in. Then call Widget.owner.getIdentifier() to get the id of the owner in the PersonRegistry, then call PersonRegistry.get(identifier) to get the owner participant
  2. When getting the Widget from the WidgetRegistry, you can call WidgetRegistry.resolve(identifier) to resolve all relationships
lgrace896
  • 312
  • 1
  • 5