<?xml version="1.0" encoding="UTF-8"?>
<!-- generator="FeedCreator 1.7.2" -->
<rss version="2.0">
    <channel>
        <title>relationship[ Search for &quot;&quot;]</title>
        <description></description>
        <link>http://xataface.com/wiki/index.php?-action=single_record_search&amp;-table=wiki&amp;page_id=%3D68&amp;-cursor=0&amp;-skip=0&amp;-limit=30&amp;-mode=list&amp;--subsearch=</link>
        <lastBuildDate>Sat, 25 May 2013 10:38:44 +0100</lastBuildDate>
        <generator>FeedCreator 1.7.2</generator>
        <item>
            <title>relationship</title>
            <link>http://www.xataface.com/wiki/relationship</link>
            <description>&lt;table&gt;&lt;thead&gt;&lt;tr&gt;&lt;th&gt;Field&lt;/th&gt;&lt;th&gt;Value&lt;/th&gt;&lt;/tr&gt;&lt;/thead&gt;&lt;tbody&gt;&lt;tr&gt;&lt;td valign=&quot;top&quot;&gt;Page name&lt;/td&gt;&lt;td valign=&quot;top&quot;&gt;relationship&lt;/td&gt;&lt;/tr&gt;&lt;tr&gt;&lt;td valign=&quot;top&quot;&gt;Page id&lt;/td&gt;&lt;td valign=&quot;top&quot;&gt;68&lt;/td&gt;&lt;/tr&gt;&lt;tr&gt;&lt;td valign=&quot;top&quot;&gt;Page title&lt;/td&gt;&lt;td valign=&quot;top&quot;&gt;The relationship fields.ini directive&lt;/td&gt;&lt;/tr&gt;&lt;tr&gt;&lt;td valign=&quot;top&quot;&gt;Content&lt;/td&gt;&lt;td valign=&quot;top&quot;&gt;&lt;p&gt;&lt;a href=&quot;/wiki/fields.ini_file&quot;&gt;Return to fields.ini file directives&lt;/a&gt;&lt;/p&gt;

&lt;table border=&quot;0&quot; cellspacing=&quot;0&quot; cellpadding=&quot;0&quot;&gt;&lt;tr&gt;&lt;td&gt;
&lt;div id=&quot;toc&quot;&gt;&lt;strong&gt;Table of Contents&lt;/strong&gt;
	&lt;div style=&quot;margin-left: 1em;&quot;&gt;&lt;a href=&quot;#toc0&quot;&gt;Synopsis&lt;/a&gt;&lt;/div&gt;
	&lt;div style=&quot;margin-left: 1em;&quot;&gt;&lt;a href=&quot;#toc1&quot;&gt;Example 1: Checkboxes to add/remove categories&lt;/a&gt;&lt;/div&gt;
	&lt;div style=&quot;margin-left: 1em;&quot;&gt;&lt;a href=&quot;#toc2&quot;&gt;Example 2: Using a grid widget&lt;/a&gt;&lt;/div&gt;
	&lt;div style=&quot;margin-left: 1em;&quot;&gt;&lt;a href=&quot;#toc3&quot;&gt;See Also&lt;/a&gt;&lt;/div&gt;
&lt;/div&gt;
&lt;/td&gt;&lt;/tr&gt;&lt;/table&gt;


&lt;h3 id=&quot;toc0&quot;&gt;Synopsis&lt;/h3&gt;
&lt;p&gt;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.&lt;/p&gt;


&lt;h3 id=&quot;toc1&quot;&gt;Example 1: Checkboxes to add/remove categories&lt;/h3&gt;
&lt;p&gt;(Note: This example requires Xataface 1.2 or higher to work)&lt;/p&gt;

&lt;p&gt;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.&lt;/p&gt;

&lt;p&gt;Table Structure: 
&lt;pre&gt;&lt;code&gt;courses:
   course_id : int (primary key)
   course_title : varchar

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

course_branches:
   course_id : int
   branch_id : int&lt;/code&gt;&lt;/pre&gt;

&lt;/p&gt;

&lt;p&gt;Relationship definition:  (from the tables/courses/&lt;a href=&quot;/wiki/relationships.ini_file&quot;&gt;relationships.ini file&lt;/a&gt;): 
&lt;pre&gt;&lt;code&gt;[branches]
    course_branches.course_id=&amp;quot;$course_id&amp;quot;
    course_branches.branch_id=branches.branch_id&lt;/code&gt;&lt;/pre&gt;

&lt;/p&gt;

&lt;p&gt;Field definitions: (from tables/courses/&lt;a href=&quot;/wiki/fields.ini_file&quot;&gt;fields.ini file&lt;/a&gt;): 
&lt;pre&gt;&lt;code&gt;[branches]
  transient=1
  relationship=branches
  widget:type=checkbox&lt;/code&gt;&lt;/pre&gt;

&lt;/p&gt;

&lt;p&gt;Things to notice: &lt;ol&gt;
    &lt;li&gt; This is a many-to-many relationship (hence the need for the course_branches join table.&lt;/li&gt;
    &lt;li&gt; The [branches] field is a transient field.&lt;/li&gt;
    &lt;li&gt; The relationship directive from the &lt;a href=&quot;/wiki/fields.ini_file&quot;&gt;fields.ini file&lt;/a&gt; references our branches relationship that was defined in the &lt;a href=&quot;/wiki/relationships.ini_file&quot;&gt;relationships.ini file&lt;/a&gt;.&lt;/li&gt;
    &lt;li&gt; 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.  &lt;/li&gt;
&lt;/ol&gt;

&lt;/p&gt;


&lt;h3 id=&quot;toc2&quot;&gt;Example 2: Using a grid widget&lt;/h3&gt;
&lt;p&gt;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 &lt;a href=&quot;/wiki/fields.ini_file&quot;&gt;fields.ini file&lt;/a&gt;.  Most of the definition can remain the same.  We only change the &lt;a href=&quot;/wiki/fields.ini_file&quot;&gt;fields.ini file&lt;/a&gt; directive:&lt;/p&gt;


&lt;pre&gt;&lt;code&gt;[branches]
  transient=1
  relationship=branches
  widget:type=grid
  widget:columns=&amp;quot;branch_name,branch_description&amp;quot;&lt;/code&gt;&lt;/pre&gt;

&lt;p&gt;In this case we are able to edit the branch name and description in each row of the grid.&lt;/p&gt;


&lt;h3 id=&quot;toc3&quot;&gt;See Also&lt;/h3&gt;
&lt;ul&gt;
    &lt;li&gt; &lt;a href=&quot;/wiki/grid&quot;&gt;The grid widget&lt;/a&gt;&lt;/li&gt;
    &lt;li&gt; &lt;a href=&quot;/wiki/checkbox&quot;&gt;The checkbox widget&lt;/a&gt;&lt;/li&gt;
    &lt;li&gt; &lt;a href=&quot;/wiki/relationships.ini_file&quot;&gt;The relationships.ini file&lt;/a&gt;&lt;/li&gt;
    &lt;li&gt; &lt;a href=&quot;/wiki/fields.ini_file&quot;&gt;The fields.ini file&lt;/a&gt;&lt;/li&gt;
&lt;/ul&gt;

&lt;/td&gt;&lt;/tr&gt;&lt;tr&gt;&lt;td valign=&quot;top&quot;&gt;Keywords&lt;/td&gt;&lt;td valign=&quot;top&quot;&gt;grid widget, relationship, checkbox&lt;/td&gt;&lt;/tr&gt;&lt;tr&gt;&lt;td valign=&quot;top&quot;&gt;Language&lt;/td&gt;&lt;td valign=&quot;top&quot;&gt;en&lt;/td&gt;&lt;/tr&gt;&lt;/tbody&gt;&lt;/table&gt;</description>
            <author>relationship</author>
        </item>
    </channel>
</rss>
