Twitter Feed

Xataface Maillist

Sign up to receive the Xataface news letter with weekly updates and development tips.

Found 1 of 138 records in table Wiki
Now Showing 1 of 1

Current Record: relationship

The relationship fields.ini directive


Return to fields.ini file directives


Certain types of widgets (e.g. grid (v1.0) and checkbox (v1.2)) support the relationship directive which allows them to effectively add/remove records from a specified relationship. This directive only works with transient fields.

Example 1: Checkboxes to add/remove categories

(Note: This example requires Xataface 1.2 or higher to work)

Suppose we have a database that keeps track of courses and the branch of research that they belong to. A course can be part of multiple branches. We want to be able to select the branches that a particular course belongs to on the edit form for that course using checkboxes.

Table Structure:

   course_id : int (primary key)
   course_title : varchar

   branch_id : int (primary key)
   branch_name : varchar
   branch_description: text

   course_id : int
   branch_id : int

Relationship definition: (from the tables/courses/relationships.ini file):


Field definitions: (from tables/courses/fields.ini file):


Things to notice:

  1. This is a many-to-many relationship (hence the need for the course_branches join table.
  2. The [branches] field is a transient field.
  3. The relationship directive from the fields.ini file references our branches relationship that was defined in the relationships.ini file.
  4. You can call the field anything that you like. There is no need for it to have the same name as the relationship. It just turned out that way in this example.

Example 2: Using a grid widget

Let's modify example 1 slightly to use a grid widget instead of checkboxes. The grid widget will allow us edit the records in a relationship using dynamic table. It automatically uses the correct widget for each column of the table according to the definition in the target table's fields.ini file. Most of the definition can remain the same. We only change the fields.ini file directive:


In this case we are able to edit the branch name and description in each row of the grid.

See Also

blog comments powered by Disqus
Powered by Xataface
(c) 2005-2019 All rights reserved