relations

An article by Gaspard Bucher

Relations let you define “roles” between your objects.

You can create new relations to use between your objects. You then use these relations to create links.

For example, if you are creating a network of people, you might want to create relations such as “friend”, “best friend”, “hero”, “mother”, “husband”, and so on.

You create these relations using the admin link “manage relations” which you access by clicking on your name when logged in (only if you have admin rights).

relations in zenadmin

Example of the relations defined for zenadmin.org

When setting up a relation, you define whether it is a “many-to-many”, “many-to-one”, “one-to-many” or “one-to-one” relationship. In the image above, the “one” is shown as a target, “many” as a list of files.

You can define links in the “drive” popup () under relations.

links definition example

Example of links defined for a node.

These links can also be defined using forms and pseudo attributes like “friend_ids”.

Once you have some people with links between them, you can use these relations in your zafu templates.

List all the friends of a person:

<r:friends do='each' join=', ' do='link'/>

List your best-friend’s favorites:

<r:best_friend>My best friend's favorites : <r:favorites do='each' join=', ' do='link'/></r:best_friend>.

Look at zafu context for more details on how to use zafu with relations.

relation group

In order to ease relation management and automatic inspection/display, you can set a “group” field on the relation. See VirtualClass for an example.

status and comment

Since version 0.9, you can set/read two fields set with a link: “status” (an integer) and “comment” (a string limited to 60 characters). To set these values you can use the drive popup or the “wife_status”, “wife_comment” pseudo attributes in forms.

You read these values by loading the nodes through a link and using the l_ syntax:

<ul do='tasks where l_status < 10'>
  <li do='each'>
    <h3 do='[name]'/>
    <p>status: <r:show attr='l_status'/> <i do='[l_comment]'/></p>
  </li>
</ul>

comments

  1. leave a comment