How To Connect Multiple Hyperledger Fabric Model (.cto) Files Using Import
#1
Following from our previous tutorial, you'll notice that we'll need more than just our Room model defined. What about when a guest wants to stay in the room, how would we model that? Well, conveniently enough, Fabric allows for multiple model files. Even better, we can use resources from one model file and connect it to a separate model file. In this tutorial, I'll show you how to accomplish this.

Step 1: Defining Our New Namespace
We'll name this model file "org.five.motel.stay.cto" and we'll define our namespace as "org.five.motel.stay" as shown below.
[Image: attachment.php?aid=38]

Step 2: Import "Room" Model
When a motel guest stays in a room, we'll need to grab things like the room number from the other model. So it's time to import this model. We do this by adding "import" following the model namespace with the name of the asset added at the end, like this.
[Image: attachment.php?aid=39]

Step 3: Creating Our Model
For our bare bones stay model, we'll need the stayId and the stayLength like the following.
[Image: attachment.php?aid=40]

Step 4: Setting The Relationship
Now it's time to set the relationship. We do this by adding another field to our asset, but rather than using "o" we use "-->" like this.
[Image: attachment.php?aid=41]

That's it! We've successfully imported resources from one model file to another.


Attached Files Thumbnail(s)
               
Reply