<?xml version="1.0" encoding="UTF-8"?>
<!-- generator="FeedCreator 1.7.2" -->
<rss version="2.0">
    <channel>
        <title>sql_delegate_method[ Search for &quot;&quot;]</title>
        <description></description>
        <link>http://xataface.com/wiki/index.php?-action=single_record_search&amp;-table=wiki&amp;page_id=%3D87&amp;-cursor=0&amp;-skip=0&amp;-limit=30&amp;-mode=list&amp;--subsearch=</link>
        <lastBuildDate>Fri, 24 May 2013 04:49:54 +0100</lastBuildDate>
        <generator>FeedCreator 1.7.2</generator>
        <item>
            <title>sql_delegate_method</title>
            <link>http://www.xataface.com/wiki/sql_delegate_method</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;sql_delegate_method&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;87&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;__sql__ Delegate Method&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;return to &lt;a href=&quot;/wiki/Delegate_class_methods&quot;&gt;Delegate class methods&lt;/a&gt;&lt;/p&gt;


&lt;h3 id=&quot;toc0&quot;&gt;Synopsis&lt;/h3&gt;
&lt;p&gt;The __sql__ delegate class method can be defined in any delegate class to specify the SQL query that should be used to fetch records for a given table.  This method overrides the __sql__&lt;a href=&quot;/wiki/index.php?-action=new&amp;-table=wiki&amp;page_name=__sql__&quot;&gt;?&lt;/a&gt; directive of the fields.ini file.  This strategy is primarily used to graft columns from another table onto the base table.&lt;/p&gt;


&lt;h5 id=&quot;toc1&quot;&gt;Use Caution&lt;/h5&gt;
&lt;p&gt;This is an advanced feature and, if used incorrectly, can muck up your application. Make sure that your SQL query includes a superset of the columns in the base table, and is a row-for-row match for the rows in the base table.  I.e. you should never use an internal join.  Always use a left join so that all of the rows of the base table are returned even if the join table doesn't have a corresponding row.&lt;/p&gt;

&lt;p&gt;If you want to simply filter a table's records, and don't need to graft any additional columns onto the table, you should use the &lt;a href=&quot;/wiki/setSecurityFilters&quot;&gt;setSecurityFilters&lt;/a&gt; method.&lt;/p&gt;


&lt;h3 id=&quot;toc2&quot;&gt;Example&lt;/h3&gt;
&lt;p&gt;Given the table foo, its delegate class:&lt;/p&gt;


&lt;pre&gt;&lt;code&gt;class tables_foo {
    function __sql__(){
        return &amp;quot;select f.*, c.category_name from foo f left join categories c on f.category_id=c.category_id&amp;quot;;
    }
}&lt;/code&gt;&lt;/pre&gt;

&lt;p&gt;This effectively grafts a column &amp;quot;category_name&amp;quot; onto the foo table based on a join with the categories table.&lt;/p&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;__sql__, SQL queries, delegate class&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>sql_delegate_method</author>
        </item>
    </channel>
</rss>
