<?xml version="1.0" encoding="UTF-8"?>
<!-- generator="FeedCreator 1.7.2" -->
<rss version="2.0">
    <channel>
        <title>Drag_and_Drop_Reordering_of_Relationships[ Search for &quot;&quot;]</title>
        <description></description>
        <link>http://xataface.com/wiki/index.php?-action=single_record_search&amp;-table=wiki&amp;page_id=%3D39&amp;-cursor=0&amp;-skip=0&amp;-limit=30&amp;-mode=list&amp;--subsearch=</link>
        <lastBuildDate>Sun, 19 May 2013 05:49:33 +0100</lastBuildDate>
        <generator>FeedCreator 1.7.2</generator>
        <item>
            <title>Drag_and_Drop_Reordering_of_Relationships</title>
            <link>http://www.xataface.com/wiki/Drag_and_Drop_Reordering_of_Relationships</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;Drag_and_Drop_Reordering_of_Relationships&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;39&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;Drag_and_Drop_Reordering_of_Relationships&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;h2 id=&quot;toc0&quot;&gt;Drag and Drop Reordering of Related Records in Xataface&lt;/h2&gt;
&lt;p&gt;One powerful aspect of Xataface is its abstraction of relationships between tables.  Once you define a relationship users can browse related records, add new and existing related records, and delete related records to or from the relationship.  For example, suppose you have a &lt;em&gt;people&lt;/em&gt; table and a &lt;em&gt;publications&lt;/em&gt;, you could define a relationship from &lt;em&gt;people&lt;/em&gt; to &lt;em&gt;publications&lt;/em&gt; to identify publications that belong to a particular person.  The table's might look something like:&lt;/p&gt;


&lt;h3 id=&quot;toc1&quot;&gt;people table&lt;/h3&gt;


&lt;table class=&quot;listing listing2&quot;&gt;
    &lt;tr&gt;
        &lt;th&gt; person_id&lt;/th&gt;
        &lt;th&gt; person_name&lt;/th&gt;
    &lt;/tr&gt;
    &lt;tr&gt;
        &lt;td&gt; 1&lt;/td&gt;
        &lt;td&gt; John Smith&lt;/td&gt;
    &lt;/tr&gt;
    &lt;tr&gt;
        &lt;td&gt; 2&lt;/td&gt;
        &lt;td&gt; Ben Stein&lt;/td&gt;
    &lt;/tr&gt;
    &lt;tr&gt;
        &lt;td&gt; 3&lt;/td&gt;
        &lt;td&gt; Harley Davidson&lt;/td&gt;
    &lt;/tr&gt;
    &lt;tr&gt;
        &lt;td&gt; 4&lt;/td&gt;
        &lt;td&gt; Trevor Linden&lt;/td&gt;
    &lt;/tr&gt;
&lt;/table&gt;


&lt;h3 id=&quot;toc2&quot;&gt;publications table&lt;/h3&gt;


&lt;table class=&quot;listing listing2&quot;&gt;
    &lt;tr&gt;
        &lt;th&gt; publication_id&lt;/th&gt;
        &lt;th&gt; owner_id&lt;/th&gt;
        &lt;th&gt; pub_title&lt;/th&gt;
    &lt;/tr&gt;
    &lt;tr&gt;
        &lt;td&gt; 1&lt;/td&gt;
        &lt;td&gt; 2&lt;/td&gt;
        &lt;td&gt; Introduction to widgetry&lt;/td&gt;
    &lt;/tr&gt;
    &lt;tr&gt;
        &lt;td&gt; 2&lt;/td&gt;
        &lt;td&gt; 2&lt;/td&gt;
        &lt;td&gt; Intermediate Widgetry&lt;/td&gt;
    &lt;/tr&gt;
    &lt;tr&gt;
        &lt;td&gt; 3&lt;/td&gt;
        &lt;td&gt; 2&lt;/td&gt;
        &lt;td&gt; Advanced Widgetry&lt;/td&gt;
    &lt;/tr&gt;
    &lt;tr&gt;
        &lt;td&gt; 4&lt;/td&gt;
        &lt;td&gt; 3&lt;/td&gt;
        &lt;td&gt; How to play the violin&lt;/td&gt;
    &lt;/tr&gt;
&lt;/table&gt;

&lt;p&gt;See &lt;a href=&quot;http://xataface.com/documentation/tutorial/getting_started/relationships&quot; onclick=&quot;window.open(this.href, '_blank'); return false;&quot;&gt;http://xataface.com/documentation/tutorial/getting_started/relationships&lt;/a&gt; for an introduction to relationships in Xataface, and how to define them.&lt;/p&gt;

&lt;p&gt;Our relationship definition in the  &lt;em&gt;people&lt;/em&gt; table's &lt;a href=&quot;/wiki/relationships.ini_file&quot;&gt;relationships.ini file&lt;/a&gt; might look something like:&lt;/p&gt;


&lt;pre&gt;&lt;code&gt;[my_pubications]
    publications.owner_id=&amp;quot;$person_id&amp;quot;&lt;/code&gt;&lt;/pre&gt;

&lt;p&gt;This indicates that any publication whose &lt;em&gt;owner_id&lt;/em&gt; column matches the current &lt;em&gt;people&lt;/em&gt; record's &lt;em&gt;person_id&lt;/em&gt; field is considered part of the relationship.  Using our example data above, this would mean that Ben Stein's &lt;em&gt;my_publications&lt;/em&gt; relationship would contain 3 records: &amp;quot;Introduction to Widgetry&amp;quot;, &amp;quot;Intermediate Widgetry&amp;quot;, and &amp;quot;Advanced Widgetry&amp;quot;.  In our Xataface application this means that in the &amp;quot;Details&amp;quot; tab for the &amp;quot;Ben Stein&amp;quot; record, we would see a sub-tab &lt;em&gt;My Publications&lt;/em&gt; which would contain a list of Ben Stein's publications.&lt;/p&gt;


&lt;h3 id=&quot;toc3&quot;&gt;Adding Publication Order&lt;/h3&gt;
&lt;p&gt;Now that we have our relationship, what if Ben Stein wants his publications to appear in a particular order whenever they are displayed to the user.  Xataface allows us to specify an &amp;quot;order&amp;quot; column for our relationship, which will cause the related records to be orderable by drag and drop (if the user has appropriate permissions).&lt;/p&gt;

&lt;ol&gt;
    &lt;li&gt; Add a field to the &lt;em&gt;publications&lt;/em&gt; table named &amp;quot;pub_order&amp;quot;&lt;/li&gt;
    &lt;li&gt; Change the relationship definition in the people table's &lt;a href=&quot;/wiki/relationships.ini_file&quot;&gt;relationships.ini file&lt;/a&gt; to tell Xataface to use the pub_order field for sorting:
&lt;pre&gt;&lt;code&gt;[my_pubications]
    publications.owner_id=&amp;quot;$person_id&amp;quot;
    metafields:order=&amp;quot;pub_order&amp;quot;&lt;/code&gt;&lt;/pre&gt;

&lt;/li&gt;
&lt;/ol&gt;

&lt;p&gt;Now load up your application and navigate to the &amp;quot;My Publications&amp;quot; tab for the &amp;quot;Ben Stein&amp;quot; record. Now you're able to drag and drop rows in your application to reorder them.&lt;/p&gt;


&lt;h3 id=&quot;toc4&quot;&gt;Permission to Reorder Records&lt;/h3&gt;
&lt;p&gt;Only users who have been assigned the &lt;em&gt;reorder_related_records&lt;/em&gt; permission for a record's relationship are allowed to reorder records of that relationship.  By default the &lt;em&gt;EDIT&lt;/em&gt; role contains this permission, as does any role that permits the user to edit the parent record of the relationship.  The &lt;em&gt;READ ONLY&lt;/em&gt; role does not contain this permission.  If you want to explicitly deny this permission for all relationships in a record, you can simply set this permission to 0 in the associated role within your application's &lt;a href=&quot;/wiki/permissions.ini_file&quot;&gt;permissions.ini file&lt;/a&gt;:&lt;/p&gt;


&lt;pre&gt;&lt;code&gt;[MY ROLE]
     reorder_related_records=0&lt;/code&gt;&lt;/pre&gt;

&lt;p&gt;For more information about permssions see:&lt;/p&gt;

&lt;ul&gt;
    &lt;li&gt; &lt;a href=&quot;/wiki/permissions.ini_file&quot;&gt;The Permissions.ini file reference&lt;/a&gt;&lt;/li&gt;
    &lt;li&gt; &lt;a href=&quot;http://xataface.com/documentation/tutorial/getting_started/permissions&quot; onclick=&quot;window.open(this.href, '_blank'); return false;&quot;&gt;Introduction to Permissions&lt;/a&gt;&lt;/li&gt;
&lt;/ul&gt;


&lt;h3 id=&quot;toc5&quot;&gt;Loading Related Records using the Xataface API&lt;/h3&gt;
&lt;p&gt;The ordering that is set via this drag and drop method is also honoured by the Xataface API when fetching related records.  You can load related records using the &lt;a href=&quot;http://dataface.weblite.ca/getRelatedRecordObjects&quot; onclick=&quot;window.open(this.href, '_blank'); return false;&quot;&gt;getRelatedRecordObjects&lt;/a&gt; method of the &lt;a href=&quot;http://dataface.weblite.ca/Dataface_Record&quot; onclick=&quot;window.open(this.href, '_blank'); return false;&quot;&gt;Dataface_Record&lt;/a&gt; class. E.g.&lt;/p&gt;


&lt;pre&gt;&lt;code&gt;$benStein = df_get_record('people', array('person_id'=&amp;gt;2));
$pubs = $benStein-&amp;gt;getRelatedRecordObjects('my_publications');
foreach ($pubs as $pub){
    echo $pub-&amp;gt;val('pub_title').'&amp;lt;br/&amp;gt;';
}&lt;/code&gt;&lt;/pre&gt;

 This will list up to the first 30 publications of Ben stein in the order prescribed by our drag and drop ordering scheme.&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>Drag_and_Drop_Reordering_of_Relationships</author>
        </item>
    </channel>
</rss>
