Creating a Data Structure
You can represent relationships and links among KiiObjects with their URIs. The combination of the URIs allows you to create various data structures such as a tree and a graph in Kii Cloud.
The simplest relationship is a unidirectional relationship.
You can represent a unidirectional relationship between two KiiObjects by storing the URI of one KiiObject as a value for a key in the other KiiObject as shown in the figure below. This figure shows URI expressions used in the Kii Cloud SDK but the same can be achieved in the REST API with KiiObject URLs.
The general flow of creating a link and referencing a KiiObject is as follows:
- Create an object B and execute the
savemethod that stores the object on the server.
- Store the URI of the object B as a value for a key (called "myLink" in this example) in the object A and execute the
savemethod of the object A.
- When you need to access the object B while processing the object A, instantiate the object B with its URI stored with the key "myLink" and execute the
refreshmethod that gets the object from the server.
If you create multiple instances of the same object with the Kii Cloud SDK, they are treated separately and their contents are not synchronized. In the above example, executing the
refresh method in Step 3 does not update the instance created in Step 1.
By combining multiple unidirectional relationships, you can represent a more complex data structure.
The next figure illustrates how you can represent a bi-directional tree structure. In this example, the child nodes have the URI of the parent node and the parent node has an array of the URIs of the child nodes.
You can reference users and groups with their ID and URI. For example, you can store user IDs of friends of an app user as a value for a key called "friend" in a KiiObject to represent a structure of a social graph.