Location: PHPKode > projects > PHP on Trax > johnpipi-trax-f599562/trax/doc/__filesource/fsource_PHPonTrax__vendortraxactive_record.php.html
<html>
<head>
<title>File Source for active_record.php</title>
<link rel="stylesheet" type="text/css" href="../media/style.css">
</head>
<body>

<table border="0" cellspacing="0" cellpadding="0" height="48" width="100%">
  <tr>
    <td class="header_top">PHPonTrax</td>
  </tr>
  <tr><td class="header_line"><img src="../media/empty.png" width="1" height="1" border="0" alt=""  /></td></tr>
  <tr>
    <td class="header_menu">
  		  [ <a href="../classtrees_PHPonTrax.html" class="menu">class tree: PHPonTrax</a> ]
		  [ <a href="../elementindex_PHPonTrax.html" class="menu">index: PHPonTrax</a> ]
		  [ <a href="../elementindex.html" class="menu">all elements</a> ]
    </td>
  </tr>
  <tr><td class="header_line"><img src="../media/empty.png" width="1" height="1" border="0" alt=""  /></td></tr>
</table>

<table width="100%" border="0" cellpadding="0" cellspacing="0">
  <tr valign="top">
    <td width="200" class="menu">
	<div id="todolist">
			<p><a href="../todolist.html">Todo List</a></p>
	</div>
      <b>Packages:</b><br />
              <a href="../li_PHPonTrax.html">PHPonTrax</a><br />
              <a href="../li_PHPonTraxTest.html">PHPonTraxTest</a><br />
            <br /><br />
                  
                </td>
    <td>
      <table cellpadding="10" cellspacing="0" width="100%" border="0"><tr><td valign="top">

<h1 align="center">Source for file active_record.php</h1>
<p>Documentation is available at <a href="../PHPonTrax/_vendor_trax_active_record_php.html">active_record.php</a></p>
<div class="php">
<div class="listing"><pre><ol><li><a name="a1"></a><span class="src-php">&lt;?php</span></li>
<li><a name="a2"></a><span class="src-doc">/**</span></li>
<li><a name="a3"></a><span class="src-doc"> *  File containing the ActiveRecord class</span></li>
<li><a name="a4"></a><span class="src-doc"> *</span></li>
<li><a name="a5"></a><span class="src-doc"> *  (PHP 5)</span></li>
<li><a name="a6"></a><span class="src-doc"> *</span></li>
<li><a name="a7"></a><span class="src-doc"> *  </span><span class="src-doc-coretag">@package</span><span class="src-doc"> PHPonTrax</span></li>
<li><a name="a8"></a><span class="src-doc"> *  </span><span class="src-doc-coretag">@version</span><span class="src-doc"> $Id: active_record.php 198 2006-04-20 16:20:30Z haas $</span></li>
<li><a name="a9"></a><span class="src-doc"> *  </span><span class="src-doc-coretag">@copyright</span><span class="src-doc"> (c) 2005 John Peterson</span></li>
<li><a name="a10"></a><span class="src-doc"> *</span></li>
<li><a name="a11"></a><span class="src-doc"> *   Permission is hereby granted, free of charge, to any person obtaining</span></li>
<li><a name="a12"></a><span class="src-doc"> *   a copy of this software and associated documentation files (the</span></li>
<li><a name="a13"></a><span class="src-doc"> *   &quot;Software&quot;), to deal in the Software without restriction, including</span></li>
<li><a name="a14"></a><span class="src-doc"> *   without limitation the rights to use, copy, modify, merge, publish,</span></li>
<li><a name="a15"></a><span class="src-doc"> *   distribute, sublicense, and/or sell copies of the Software, and to</span></li>
<li><a name="a16"></a><span class="src-doc"> *   permit persons to whom the Software is furnished to do so, subject to</span></li>
<li><a name="a17"></a><span class="src-doc"> *   the following conditions:</span></li>
<li><a name="a18"></a><span class="src-doc"> *</span></li>
<li><a name="a19"></a><span class="src-doc"> *   The above copyright notice and this permission notice shall be</span></li>
<li><a name="a20"></a><span class="src-doc"> *   included in all copies or substantial portions of the Software.</span></li>
<li><a name="a21"></a><span class="src-doc"> *</span></li>
<li><a name="a22"></a><span class="src-doc"> *   THE SOFTWARE IS PROVIDED &quot;AS IS&quot;, WITHOUT WARRANTY OF ANY KIND,</span></li>
<li><a name="a23"></a><span class="src-doc"> *   EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF</span></li>
<li><a name="a24"></a><span class="src-doc"> *   MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND</span></li>
<li><a name="a25"></a><span class="src-doc"> *   NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE</span></li>
<li><a name="a26"></a><span class="src-doc"> *   LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION</span></li>
<li><a name="a27"></a><span class="src-doc"> *   OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION</span></li>
<li><a name="a28"></a><span class="src-doc"> *   WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.</span></li>
<li><a name="a29"></a><span class="src-doc"> */</span></li>
<li><a name="a30"></a>&nbsp;</li>
<li><a name="a31"></a><span class="src-doc">/**</span></li>
<li><a name="a32"></a><span class="src-doc"> *  Load the </span><span class="src-doc-inlinetag">{@link http://pear.php.net/manual/en/package.pear.php PEAR base class}</span></li>
<li><a name="a33"></a><span class="src-doc"> */</span></li>
<li><a name="a34"></a><span class="src-inc">require_once</span><span class="src-sym">(</span><span class="src-str">'PEAR.php'</span><span class="src-sym">)</span><span class="src-sym">;</span></li>
<li><a name="a35"></a>&nbsp;</li>
<li><a name="a36"></a><span class="src-doc">/**</span></li>
<li><a name="a37"></a><span class="src-doc"> *  Load the </span><span class="src-doc-inlinetag">{@link http://pear.php.net/manual/en/package.database.db.php PEAR DB package}</span></li>
<li><a name="a38"></a><span class="src-doc"> */</span></li>
<li><a name="a39"></a><span class="src-inc">require_once</span><span class="src-sym">(</span><span class="src-str">'DB.php'</span><span class="src-sym">)</span><span class="src-sym">;</span></li>
<li><a name="a40"></a>&nbsp;</li>
<li><a name="a41"></a><span class="src-doc">/**</span></li>
<li><a name="a42"></a><span class="src-doc"> *  Base class for the ActiveRecord design pattern</span></li>
<li><a name="a43"></a><span class="src-doc"> *</span></li>
<li><a name="a44"></a><span class="src-doc"> *  &lt;p&gt;Each subclass of this class is associated with a database table</span></li>
<li><a name="a45"></a><span class="src-doc"> *  in the Model section of the Model-View-Controller architecture.</span></li>
<li><a name="a46"></a><span class="src-doc"> *  By convention, the name of each subclass is the CamelCase singular</span></li>
<li><a name="a47"></a><span class="src-doc"> *  form of the table name, which is in the lower_case_underscore</span></li>
<li><a name="a48"></a><span class="src-doc"> *  plural notation.  For example,</span></li>
<li><a name="a49"></a><span class="src-doc"> *  a table named &quot;order_details&quot; would be associated with a subclass</span></li>
<li><a name="a50"></a><span class="src-doc"> *  of ActiveRecord named &quot;OrderDetail&quot;, and a table named &quot;people&quot;</span></li>
<li><a name="a51"></a><span class="src-doc"> *  would be associated with subclass &quot;Person&quot;.  See the tutorial</span></li>
<li><a name="a52"></a><span class="src-doc"> *  </span><span class="src-doc-inlinetag">{@tutorial PHPonTrax/naming.pkg}</span><span class="src-doc">&lt;/p&gt;</span></li>
<li><a name="a53"></a><span class="src-doc"> *</span></li>
<li><a name="a54"></a><span class="src-doc"> *  &lt;p&gt;For a discussion of the ActiveRecord design pattern, see</span></li>
<li><a name="a55"></a><span class="src-doc"> *  &quot;Patterns of Enterprise</span></li>
<li><a name="a56"></a><span class="src-doc"> *  Application Architecture&quot; by Martin Fowler, pp. 160-164.&lt;/p&gt;</span></li>
<li><a name="a57"></a><span class="src-doc"> *</span></li>
<li><a name="a58"></a><span class="src-doc"> *  &lt;p&gt;Unit tester: </span><span class="src-doc-inlinetag">{@link ActiveRecordTest}</span><span class="src-doc">&lt;/p&gt;</span></li>
<li><a name="a59"></a><span class="src-doc"> *</span></li>
<li><a name="a60"></a><span class="src-doc"> *  </span><span class="src-doc-coretag">@tutorial</span><span class="src-doc"> PHPonTrax/ActiveRecord.cls</span></li>
<li><a name="a61"></a><span class="src-doc"> */</span></li>
<li><a name="a62"></a><span class="src-key">class </span><a href="../PHPonTrax/ActiveRecord.html">ActiveRecord</a> <span class="src-sym">{</span></li>
<li><a name="a63"></a>&nbsp;</li>
<li><a name="a64"></a>    <span class="src-doc">/**</span></li>
<li><a name="a65"></a><span class="src-doc">     *  Reference to the database object</span></li>
<li><a name="a66"></a><span class="src-doc">     *</span></li>
<li><a name="a67"></a><span class="src-doc">     *  Reference to the database object returned by</span></li>
<li><a name="a68"></a><span class="src-doc">     *  </span><span class="src-doc-inlinetag">{@link http://pear.php.net/manual/en/package.database.db.db.connect.php  PEAR DB::Connect()}</span></li>
<li><a name="a69"></a><span class="src-doc">     *  </span><span class="src-doc-coretag">@var </span><span class="src-doc-type">object </span><span class="src-doc-type">DB </span></li>
<li><a name="a70"></a><span class="src-doc">     *   </span><span class="src-doc">see</span></li>
<li><a name="a71"></a><span class="src-doc">     *   </span><span class="src-doc-inlinetag">{@link http://pear.php.net/manual/en/package.database.db.php PEAR DB}</span></li>
<li><a name="a72"></a><span class="src-doc">     */</span></li>
<li><a name="a73"></a>    <span class="src-key">private </span><span class="src-key">static </span><span class="src-var">$db </span>= <span class="src-id">null</span><span class="src-sym">;</span></li>
<li><a name="a74"></a>&nbsp;</li>
<li><a name="a75"></a>    <span class="src-doc">/**</span></li>
<li><a name="a76"></a><span class="src-doc">     *  Description of a row in the associated table in the database</span></li>
<li><a name="a77"></a><span class="src-doc">     *</span></li>
<li><a name="a78"></a><span class="src-doc">     *  &lt;p&gt;Retrieved from the RDBMS by </span><span class="src-doc-inlinetag">{@link set_content_columns()}</span><span class="src-doc">.</span></li>
<li><a name="a79"></a><span class="src-doc">     *  See </span><span class="src-doc-inlinetag">{@link }</span></li>
<li><a name="a80"></a><span class="src-doc">     *  http://pear.php.net/manual/en/package.database.db.db-common.tableinfo.php</span></li>
<li><a name="a81"></a><span class="src-doc">     *  DB_common::tableInfo()} for the format.  &lt;b&gt;NOTE:&lt;/b&gt; Some</span></li>
<li><a name="a82"></a><span class="src-doc">     *  RDBMS's don't return all values.&lt;/p&gt;</span></li>
<li><a name="a83"></a><span class="src-doc">     *</span></li>
<li><a name="a84"></a><span class="src-doc">     *  &lt;p&gt;An additional element 'human_name' is added to each column</span></li>
<li><a name="a85"></a><span class="src-doc">     *  by </span><span class="src-doc-inlinetag">{@link set_content_columns()}</span><span class="src-doc">.  The actual value contained</span></li>
<li><a name="a86"></a><span class="src-doc">     *  in each column is stored in an object variable with the name</span></li>
<li><a name="a87"></a><span class="src-doc">     *  given by the 'name' element of the column description for each</span></li>
<li><a name="a88"></a><span class="src-doc">     *  column.&lt;/p&gt;</span></li>
<li><a name="a89"></a><span class="src-doc">     *</span></li>
<li><a name="a90"></a><span class="src-doc">     *  &lt;p&gt;&lt;b&gt;NOTE:&lt;/b&gt;The information from the database about which</span></li>
<li><a name="a91"></a><span class="src-doc">     *  columns are primary keys is &lt;b&gt;not used&lt;/b&gt;.  Instead, the</span></li>
<li><a name="a92"></a><span class="src-doc">     *  primary keys in the table are listed in </span><span class="src-doc-inlinetag">{@link $primary_keys}</span><span class="src-doc">,</span></li>
<li><a name="a93"></a><span class="src-doc">     *  which is maintained independently.&lt;/p&gt;</span></li>
<li><a name="a94"></a><span class="src-doc">     *  </span><span class="src-doc-coretag">@var </span><span class="src-doc-type">string[] </span></li>
<li><a name="a95"></a><span class="src-doc">     *  </span><span class="src-doc-coretag">@see</span><span class="src-doc"> $primary_keys</span></li>
<li><a name="a96"></a><span class="src-doc">     *  </span><span class="src-doc-coretag">@see</span><span class="src-doc"> quoted_attributes()</span></li>
<li><a name="a97"></a><span class="src-doc">     *  </span><span class="src-doc-coretag">@see</span><span class="src-doc"> __set()</span></li>
<li><a name="a98"></a><span class="src-doc">     */</span></li>
<li><a name="a99"></a>    <span class="src-key">public </span><a href="../PHPonTrax/ActiveRecord.html#var$content_columns">$content_columns</a> = <span class="src-id">null</span><span class="src-sym">; </span><span class="src-comm"># info about each column in the table</span></li>
<li><a name="a100"></a>&nbsp;</li>
<li><a name="a100"></a>    </li>
<li><a name="a101"></a>    <span class="src-doc">/**</span></li>
<li><a name="a102"></a><span class="src-doc">     *  Table name</span></li>
<li><a name="a103"></a><span class="src-doc">     *</span></li>
<li><a name="a104"></a><span class="src-doc">     *  Name of the table in the database associated with the subclass.</span></li>
<li><a name="a105"></a><span class="src-doc">     *  Normally set to the pluralized lower case underscore form of</span></li>
<li><a name="a106"></a><span class="src-doc">     *  the class name by the constructor.  May be overridden.</span></li>
<li><a name="a107"></a><span class="src-doc">     *  </span><span class="src-doc-coretag">@var </span><span class="src-doc-type">string </span></li>
<li><a name="a108"></a><span class="src-doc">     */</span></li>
<li><a name="a109"></a>    <span class="src-key">public </span><a href="../PHPonTrax/ActiveRecord.html#var$table_name">$table_name</a> = <span class="src-id">null</span><span class="src-sym">;</span></li>
<li><a name="a110"></a>&nbsp;</li>
<li><a name="a111"></a>    <span class="src-doc">/**</span></li>
<li><a name="a112"></a><span class="src-doc">     *  Database name override</span></li>
<li><a name="a113"></a><span class="src-doc">     *</span></li>
<li><a name="a114"></a><span class="src-doc">     *  Name of the database to use, if you are not using the value</span></li>
<li><a name="a115"></a><span class="src-doc">     *  read from file config/database.ini</span></li>
<li><a name="a116"></a><span class="src-doc">     *  </span><span class="src-doc-coretag">@var </span><span class="src-doc-type">string </span></li>
<li><a name="a117"></a><span class="src-doc">     */</span></li>
<li><a name="a118"></a>    <span class="src-key">public </span><a href="../PHPonTrax/ActiveRecord.html#var$database_name">$database_name</a> = <span class="src-id">null</span><span class="src-sym">;</span></li>
<li><a name="a119"></a>&nbsp;</li>
<li><a name="a120"></a>    <span class="src-doc">/**</span></li>
<li><a name="a121"></a><span class="src-doc">     *  Mode to use when fetching data from database</span></li>
<li><a name="a122"></a><span class="src-doc">     *</span></li>
<li><a name="a123"></a><span class="src-doc">     *  See </span><span class="src-doc-inlinetag">{@link }</span></li>
<li><a name="a124"></a><span class="src-doc">     *  http://pear.php.net/manual/en/package.database.db.db-common.setfetchmode.php</span></li>
<li><a name="a125"></a><span class="src-doc">     *  the relevant PEAR DB class documentation}</span></li>
<li><a name="a126"></a><span class="src-doc">     *  </span><span class="src-doc-coretag">@var </span><span class="src-doc-type">integer </span></li>
<li><a name="a127"></a><span class="src-doc">     */</span></li>
<li><a name="a128"></a>    <span class="src-key">public </span><a href="../PHPonTrax/ActiveRecord.html#var$fetch_mode">$fetch_mode</a> = <span class="src-id">DB_FETCHMODE_ASSOC</span><span class="src-sym">;</span></li>
<li><a name="a129"></a>&nbsp;</li>
<li><a name="a130"></a>    <span class="src-doc">/**</span></li>
<li><a name="a131"></a><span class="src-doc">     *  Force reconnect to database</span></li>
<li><a name="a132"></a><span class="src-doc">     *</span></li>
<li><a name="a133"></a><span class="src-doc">     *  </span><span class="src-doc-coretag">@var </span><span class="src-doc-type">boolean </span></li>
<li><a name="a134"></a><span class="src-doc">     */</span></li>
<li><a name="a135"></a>    <span class="src-key">public </span><a href="../PHPonTrax/ActiveRecord.html#var$force_reconnect">$force_reconnect</a> = <span class="src-id">false</span><span class="src-sym">; </span><span class="src-comm"># should we force a connection everytime</span></li>
<li><a name="a136"></a>        <span class="src-key">public </span><a href="../PHPonTrax/ActiveRecord.html#var$index_on">$index_on</a> = <span class="src-str">&quot;id&quot;</span><span class="src-sym">; </span><span class="src-comm"># find_all returns an array of objects each object index is off of this field</span></li>
<li><a name="a137"></a>&nbsp;</li>
<li><a name="a138"></a>    <span class="src-comm"># Table associations</span></li>
<li><a name="a139"></a>        <span class="src-doc">/**</span></li>
<li><a name="a140"></a><span class="src-doc">     *  </span><span class="src-doc-coretag">@todo</span><span class="src-doc"> Document this variable</span></li>
<li><a name="a141"></a><span class="src-doc">     *  </span><span class="src-doc-coretag">@var </span><span class="src-doc-type">string[] </span></li>
<li><a name="a142"></a><span class="src-doc">     */</span></li>
<li><a name="a143"></a>    <span class="src-key">protected </span><a href="../PHPonTrax/ActiveRecord.html#var$has_many">$has_many</a> = <span class="src-id">null</span><span class="src-sym">;</span></li>
<li><a name="a144"></a>&nbsp;</li>
<li><a name="a145"></a>    <span class="src-doc">/**</span></li>
<li><a name="a146"></a><span class="src-doc">     *  </span><span class="src-doc-coretag">@todo</span><span class="src-doc"> Document this variable</span></li>
<li><a name="a147"></a><span class="src-doc">     *  </span><span class="src-doc-coretag">@var </span><span class="src-doc-type">string[] </span></li>
<li><a name="a148"></a><span class="src-doc">     */</span></li>
<li><a name="a149"></a>    <span class="src-key">protected </span><a href="../PHPonTrax/ActiveRecord.html#var$has_one">$has_one</a> = <span class="src-id">null</span><span class="src-sym">;</span></li>
<li><a name="a150"></a>&nbsp;</li>
<li><a name="a151"></a>    <span class="src-doc">/**</span></li>
<li><a name="a152"></a><span class="src-doc">     *  </span><span class="src-doc-coretag">@todo</span><span class="src-doc"> Document this variable</span></li>
<li><a name="a153"></a><span class="src-doc">     *  </span><span class="src-doc-coretag">@var </span><span class="src-doc-type">string[] </span></li>
<li><a name="a154"></a><span class="src-doc">     */</span></li>
<li><a name="a155"></a>    <span class="src-key">protected </span><a href="../PHPonTrax/ActiveRecord.html#var$has_and_belongs_to_many">$has_and_belongs_to_many</a> = <span class="src-id">null</span><span class="src-sym">;</span></li>
<li><a name="a156"></a>&nbsp;</li>
<li><a name="a157"></a>    <span class="src-doc">/**</span></li>
<li><a name="a158"></a><span class="src-doc">     *  </span><span class="src-doc-coretag">@todo</span><span class="src-doc"> Document this variable</span></li>
<li><a name="a159"></a><span class="src-doc">     *  </span><span class="src-doc-coretag">@var </span><span class="src-doc-type">string[] </span></li>
<li><a name="a160"></a><span class="src-doc">     */</span></li>
<li><a name="a161"></a>    <span class="src-key">protected </span><a href="../PHPonTrax/ActiveRecord.html#var$belongs_to">$belongs_to</a> = <span class="src-id">null</span><span class="src-sym">;</span></li>
<li><a name="a162"></a>&nbsp;</li>
<li><a name="a163"></a>    <span class="src-doc">/**</span></li>
<li><a name="a164"></a><span class="src-doc">     *  </span><span class="src-doc-coretag">@todo</span><span class="src-doc"> Document this variable</span></li>
<li><a name="a165"></a><span class="src-doc">     *  </span><span class="src-doc-coretag">@var </span><span class="src-doc-type">string[] </span></li>
<li><a name="a166"></a><span class="src-doc">     */</span></li>
<li><a name="a167"></a>    <span class="src-key">protected </span><a href="../PHPonTrax/ActiveRecord.html#var$habtm_attributes">$habtm_attributes</a> = <span class="src-id">null</span><span class="src-sym">;</span></li>
<li><a name="a168"></a>&nbsp;</li>
<li><a name="a169"></a>    <span class="src-doc">/**</span></li>
<li><a name="a170"></a><span class="src-doc">     *  </span><span class="src-doc-coretag">@todo</span><span class="src-doc"> Document this property</span></li>
<li><a name="a171"></a><span class="src-doc">     */</span></li>
<li><a name="a172"></a>    <span class="src-key">protected </span><a href="../PHPonTrax/ActiveRecord.html#var$save_associations">$save_associations</a> = <span class="src-key">array</span><span class="src-sym">(</span><span class="src-sym">)</span><span class="src-sym">;</span></li>
<li><a name="a173"></a>    </li>
<li><a name="a174"></a>    <span class="src-doc">/**</span></li>
<li><a name="a175"></a><span class="src-doc">     *  </span><span class="src-doc-coretag">@todo</span><span class="src-doc"> Document this property</span></li>
<li><a name="a176"></a><span class="src-doc">     *  </span><span class="src-doc-coretag">@var </span><span class="src-doc-type">boolean </span></li>
<li><a name="a177"></a><span class="src-doc">     */</span></li>
<li><a name="a178"></a>    <span class="src-key">public </span><a href="../PHPonTrax/ActiveRecord.html#var$auto_save_associations">$auto_save_associations</a> = <span class="src-id">true</span><span class="src-sym">; </span><span class="src-comm"># where or not to auto save defined associations if set</span></li>
<li><a name="a179"></a>&nbsp;</li>
<li><a name="a179"></a>    </li>
<li><a name="a180"></a>    <span class="src-doc">/**</span></li>
<li><a name="a181"></a><span class="src-doc">     *  Whether this object represents a new record</span></li>
<li><a name="a182"></a><span class="src-doc">     *</span></li>
<li><a name="a183"></a><span class="src-doc">     *  true =&gt; This object was created without reading a row from the</span></li>
<li><a name="a184"></a><span class="src-doc">     *          database, so use SQL 'INSERT' to put it in the database.</span></li>
<li><a name="a185"></a><span class="src-doc">     *  false =&gt; This object was a row read from the database, so use</span></li>
<li><a name="a186"></a><span class="src-doc">     *           SQL 'UPDATE' to update database with new values.</span></li>
<li><a name="a187"></a><span class="src-doc">     *  </span><span class="src-doc-coretag">@var </span><span class="src-doc-type">boolean </span></li>
<li><a name="a188"></a><span class="src-doc">     */</span></li>
<li><a name="a189"></a>    <span class="src-key">protected </span><a href="../PHPonTrax/ActiveRecord.html#var$new_record">$new_record</a> = <span class="src-id">true</span><span class="src-sym">;</span></li>
<li><a name="a190"></a>&nbsp;</li>
<li><a name="a191"></a>    <span class="src-doc">/**</span></li>
<li><a name="a192"></a><span class="src-doc">     *  Names of automatic update timestamp columns</span></li>
<li><a name="a193"></a><span class="src-doc">     *</span></li>
<li><a name="a194"></a><span class="src-doc">     *  When a row containing one of these columns is updated and</span></li>
<li><a name="a195"></a><span class="src-doc">     *  </span><span class="src-doc-inlinetag">{@link $auto_timestamps}</span><span class="src-doc"> is true, update the contents of the</span></li>
<li><a name="a196"></a><span class="src-doc">     *  timestamp columns with the current date and time.</span></li>
<li><a name="a197"></a><span class="src-doc">     *  </span><span class="src-doc-coretag">@see</span><span class="src-doc"> $auto_timestamps</span></li>
<li><a name="a198"></a><span class="src-doc">     *  </span><span class="src-doc-coretag">@see</span><span class="src-doc"> $auto_create_timestamps</span></li>
<li><a name="a199"></a><span class="src-doc">     *  </span><span class="src-doc-coretag">@var </span><span class="src-doc-type">string[] </span></li>
<li><a name="a200"></a><span class="src-doc">     */</span></li>
<li><a name="a201"></a>    <span class="src-key">protected </span><a href="../PHPonTrax/ActiveRecord.html#var$auto_update_timestamps">$auto_update_timestamps</a> = <span class="src-key">array</span><span class="src-sym">(</span><span class="src-str">&quot;updated_at&quot;</span><span class="src-sym">,</span><span class="src-str">&quot;updated_on&quot;</span><span class="src-sym">)</span><span class="src-sym">;</span></li>
<li><a name="a202"></a>&nbsp;</li>
<li><a name="a203"></a>    <span class="src-doc">/**</span></li>
<li><a name="a204"></a><span class="src-doc">     *  Names of automatic create timestamp columns</span></li>
<li><a name="a205"></a><span class="src-doc">     *</span></li>
<li><a name="a206"></a><span class="src-doc">     *  When a row containing one of these columns is created and</span></li>
<li><a name="a207"></a><span class="src-doc">     *  </span><span class="src-doc-inlinetag">{@link $auto_timestamps}</span><span class="src-doc"> is true, store the current date and</span></li>
<li><a name="a208"></a><span class="src-doc">     *  time in the timestamp columns.</span></li>
<li><a name="a209"></a><span class="src-doc">     *  </span><span class="src-doc-coretag">@see</span><span class="src-doc"> $auto_timestamps</span></li>
<li><a name="a210"></a><span class="src-doc">     *  </span><span class="src-doc-coretag">@see</span><span class="src-doc"> $auto_update_timestamps</span></li>
<li><a name="a211"></a><span class="src-doc">     *  </span><span class="src-doc-coretag">@var </span><span class="src-doc-type">string[] </span></li>
<li><a name="a212"></a><span class="src-doc">     */</span></li>
<li><a name="a213"></a>    <span class="src-key">protected </span><a href="../PHPonTrax/ActiveRecord.html#var$auto_create_timestamps">$auto_create_timestamps</a> = <span class="src-key">array</span><span class="src-sym">(</span><span class="src-str">&quot;created_at&quot;</span><span class="src-sym">,</span><span class="src-str">&quot;created_on&quot;</span><span class="src-sym">)</span><span class="src-sym">;</span></li>
<li><a name="a214"></a>&nbsp;</li>
<li><a name="a215"></a>    <span class="src-doc">/**</span></li>
<li><a name="a216"></a><span class="src-doc">     *  Date format for use with auto timestamping</span></li>
<li><a name="a217"></a><span class="src-doc">     *</span></li>
<li><a name="a218"></a><span class="src-doc">     *  The format for this should be compatiable with the php date() function.</span></li>
<li><a name="a219"></a><span class="src-doc">     *  http://www.php.net/date</span></li>
<li><a name="a220"></a><span class="src-doc">     *  </span><span class="src-doc-coretag">@var </span><span class="src-doc-type">string </span></li>
<li><a name="a221"></a><span class="src-doc">     */</span></li>
<li><a name="a222"></a>     <span class="src-key">protected </span><a href="../PHPonTrax/ActiveRecord.html#var$date_format">$date_format</a> = <span class="src-str">&quot;Y-m-d&quot;</span><span class="src-sym">;</span></li>
<li><a name="a223"></a>&nbsp;</li>
<li><a name="a224"></a>    <span class="src-doc">/**</span></li>
<li><a name="a225"></a><span class="src-doc">     *  Time format for use with auto timestamping</span></li>
<li><a name="a226"></a><span class="src-doc">     *</span></li>
<li><a name="a227"></a><span class="src-doc">     *  The format for this should be compatiable with the php date() function.</span></li>
<li><a name="a228"></a><span class="src-doc">     *  http://www.php.net/date</span></li>
<li><a name="a229"></a><span class="src-doc">     *  </span><span class="src-doc-coretag">@var </span><span class="src-doc-type">string </span></li>
<li><a name="a230"></a><span class="src-doc">     */    </span></li>
<li><a name="a231"></a>     <span class="src-key">protected </span><a href="../PHPonTrax/ActiveRecord.html#var$time_format">$time_format</a> = <span class="src-str">&quot;H:i:s&quot;</span><span class="src-sym">;</span></li>
<li><a name="a232"></a>       </li>
<li><a name="a233"></a>    <span class="src-doc">/**</span></li>
<li><a name="a234"></a><span class="src-doc">     *  Whether to keep date/datetime fields NULL if not set</span></li>
<li><a name="a235"></a><span class="src-doc">     *</span></li>
<li><a name="a236"></a><span class="src-doc">     *  true =&gt; If date field is not set it try to preserve NULL</span></li>
<li><a name="a237"></a><span class="src-doc">     *  false =&gt; Don't try to preserve NULL if field is already NULL</span></li>
<li><a name="a238"></a><span class="src-doc">     *  </span><span class="src-doc-coretag">@var </span><span class="src-doc-type">boolean </span></li>
<li><a name="a239"></a><span class="src-doc">     */       </span></li>
<li><a name="a240"></a>     <span class="src-key">protected </span><a href="../PHPonTrax/ActiveRecord.html#var$preserve_null_dates">$preserve_null_dates</a> = <span class="src-id">true</span><span class="src-sym">;</span></li>
<li><a name="a241"></a>&nbsp;</li>
<li><a name="a242"></a>    <span class="src-doc">/**</span></li>
<li><a name="a243"></a><span class="src-doc">     *  SQL aggregate functions that may be applied to the associated</span></li>
<li><a name="a244"></a><span class="src-doc">     *  table.</span></li>
<li><a name="a245"></a><span class="src-doc">     *</span></li>
<li><a name="a246"></a><span class="src-doc">     *  SQL defines aggregate functions AVG, COUNT, MAX, MIN and SUM.</span></li>
<li><a name="a247"></a><span class="src-doc">     *  Not all of these functions are implemented by all DBMS's</span></li>
<li><a name="a248"></a><span class="src-doc">     *  </span><span class="src-doc-coretag">@var </span><span class="src-doc-type">string[] </span></li>
<li><a name="a249"></a><span class="src-doc">     */</span></li>
<li><a name="a250"></a>    <span class="src-key">protected </span><a href="../PHPonTrax/ActiveRecord.html#var$aggregrations">$aggregrations</a> = <span class="src-key">array</span><span class="src-sym">(</span><span class="src-str">&quot;count&quot;</span><span class="src-sym">,</span><span class="src-str">&quot;sum&quot;</span><span class="src-sym">,</span><span class="src-str">&quot;avg&quot;</span><span class="src-sym">,</span><span class="src-str">&quot;max&quot;</span><span class="src-sym">,</span><span class="src-str">&quot;min&quot;</span><span class="src-sym">)</span><span class="src-sym">;</span></li>
<li><a name="a251"></a>     </li>
<li><a name="a252"></a>    <span class="src-doc">/**</span></li>
<li><a name="a253"></a><span class="src-doc">     *  Primary key of the associated table</span></li>
<li><a name="a254"></a><span class="src-doc">     *</span></li>
<li><a name="a255"></a><span class="src-doc">     *  Array element(s) name the primary key column(s), as used to</span></li>
<li><a name="a256"></a><span class="src-doc">     *  specify the row to be updated or deleted.  To be a primary key</span></li>
<li><a name="a257"></a><span class="src-doc">     *  a column must be listed both here and in </span><span class="src-doc-inlinetag">{@link }</span></li>
<li><a name="a258"></a><span class="src-doc">     *  $content_columns}.  &lt;b&gt;NOTE:&lt;/b&gt;This</span></li>
<li><a name="a259"></a><span class="src-doc">     *  field is maintained by hand.  It is not derived from the table</span></li>
<li><a name="a260"></a><span class="src-doc">     *  description read from the database.</span></li>
<li><a name="a261"></a><span class="src-doc">     *  </span><span class="src-doc-coretag">@var </span><span class="src-doc-type">string[] </span></li>
<li><a name="a262"></a><span class="src-doc">     *  </span><span class="src-doc-coretag">@see</span><span class="src-doc"> $content_columns</span></li>
<li><a name="a263"></a><span class="src-doc">     *  </span><span class="src-doc-coretag">@see</span><span class="src-doc"> find()</span></li>
<li><a name="a264"></a><span class="src-doc">     *  </span><span class="src-doc-coretag">@see</span><span class="src-doc"> find_all()</span></li>
<li><a name="a265"></a><span class="src-doc">     *  </span><span class="src-doc-coretag">@see</span><span class="src-doc"> find_first()</span></li>
<li><a name="a266"></a><span class="src-doc">     */</span></li>
<li><a name="a267"></a>    <span class="src-key">public </span><a href="../PHPonTrax/ActiveRecord.html#var$primary_keys">$primary_keys</a> = <span class="src-key">array</span><span class="src-sym">(</span><span class="src-str">&quot;id&quot;</span><span class="src-sym">)</span><span class="src-sym">;</span></li>
<li><a name="a268"></a>&nbsp;</li>
<li><a name="a269"></a>    <span class="src-doc">/**</span></li>
<li><a name="a270"></a><span class="src-doc">     *  Default for how many rows to return from </span><span class="src-doc-inlinetag">{@link find_all()}</span></li>
<li><a name="a271"></a><span class="src-doc">     *  </span><span class="src-doc-coretag">@var </span><span class="src-doc-type">integer </span></li>
<li><a name="a272"></a><span class="src-doc">     */</span></li>
<li><a name="a273"></a>    <span class="src-key">public </span><a href="../PHPonTrax/ActiveRecord.html#var$rows_per_page_default">$rows_per_page_default</a> = <span class="src-num">20</span><span class="src-sym">;</span></li>
<li><a name="a274"></a>&nbsp;</li>
<li><a name="a275"></a>    <span class="src-doc">/**</span></li>
<li><a name="a276"></a><span class="src-doc">     *  </span><span class="src-doc-coretag">@todo</span><span class="src-doc"> Document this variable</span></li>
<li><a name="a277"></a><span class="src-doc">     */</span></li>
<li><a name="a278"></a>    <span class="src-key">public </span><a href="../PHPonTrax/ActiveRecord.html#var$display">$display</a> = <span class="src-num">10</span><span class="src-sym">; </span><span class="src-comm"># Pagination how many numbers in the list &lt;&lt; &lt; 1 2 3 4 &gt; &gt;&gt;</span></li>
<li><a name="a279"></a>&nbsp;</li>
<li><a name="a279"></a>    </li>
<li><a name="a280"></a>    <span class="src-doc">/**</span></li>
<li><a name="a281"></a><span class="src-doc">     *  Description of non-fatal errors found</span></li>
<li><a name="a282"></a><span class="src-doc">     *</span></li>
<li><a name="a283"></a><span class="src-doc">     *  For every non-fatal error found, an element describing the</span></li>
<li><a name="a284"></a><span class="src-doc">     *  error is added to $errors.  Initialized to an empty array in</span></li>
<li><a name="a285"></a><span class="src-doc">     *  </span><span class="src-doc-inlinetag">{@link valid()}</span><span class="src-doc"> before validating object.  When an error</span></li>
<li><a name="a286"></a><span class="src-doc">     *  message is associated with a particular attribute, the message</span></li>
<li><a name="a287"></a><span class="src-doc">     *  should be stored with the attribute name as its key.  If the</span></li>
<li><a name="a288"></a><span class="src-doc">     *  message is independent of attributes, store it with a numeric</span></li>
<li><a name="a289"></a><span class="src-doc">     *  key beginning with 0.</span></li>
<li><a name="a290"></a><span class="src-doc">     *  </span></li>
<li><a name="a291"></a><span class="src-doc">     *  </span><span class="src-doc-coretag">@var </span><span class="src-doc-type">string[] </span></li>
<li><a name="a292"></a><span class="src-doc">     *  </span><span class="src-doc-coretag">@see</span><span class="src-doc"> add_error()</span></li>
<li><a name="a293"></a><span class="src-doc">     *  </span><span class="src-doc-coretag">@see</span><span class="src-doc"> get_errors()</span></li>
<li><a name="a294"></a><span class="src-doc">     */</span></li>
<li><a name="a295"></a>    <span class="src-key">public </span><a href="../PHPonTrax/ActiveRecord.html#var$errors">$errors</a> = <span class="src-key">array</span><span class="src-sym">(</span><span class="src-sym">)</span><span class="src-sym">;</span></li>
<li><a name="a296"></a>&nbsp;</li>
<li><a name="a297"></a>    <span class="src-doc">/**</span></li>
<li><a name="a298"></a><span class="src-doc">     *  Whether to automatically update timestamps in certain columns</span></li>
<li><a name="a299"></a><span class="src-doc">     *</span></li>
<li><a name="a300"></a><span class="src-doc">     *  </span><span class="src-doc-coretag">@see</span><span class="src-doc"> $auto_create_timestamps</span></li>
<li><a name="a301"></a><span class="src-doc">     *  </span><span class="src-doc-coretag">@see</span><span class="src-doc"> $auto_update_timestamps</span></li>
<li><a name="a302"></a><span class="src-doc">     *  </span><span class="src-doc-coretag">@var </span><span class="src-doc-type">boolean </span></li>
<li><a name="a303"></a><span class="src-doc">     */</span></li>
<li><a name="a304"></a>    <span class="src-key">public </span><a href="../PHPonTrax/ActiveRecord.html#var$auto_timestamps">$auto_timestamps</a> = <span class="src-id">true</span><span class="src-sym">;</span></li>
<li><a name="a305"></a>&nbsp;</li>
<li><a name="a306"></a>    <span class="src-doc">/**</span></li>
<li><a name="a307"></a><span class="src-doc">     *  </span><span class="src-doc-coretag">@todo</span><span class="src-doc"> Document this variable</span></li>
<li><a name="a308"></a><span class="src-doc">     */</span></li>
<li><a name="a309"></a>    <span class="src-key">public </span><a href="../PHPonTrax/ActiveRecord.html#var$auto_save_habtm">$auto_save_habtm</a> = <span class="src-id">true</span><span class="src-sym">; </span><span class="src-comm"># auto insert / update $has_and_belongs_to_many tables</span></li>
<li><a name="a310"></a>&nbsp;</li>
<li><a name="a310"></a>    </li>
<li><a name="a311"></a>    <span class="src-doc">/**</span></li>
<li><a name="a312"></a><span class="src-doc">     *  </span><span class="src-doc-coretag">@todo</span><span class="src-doc"> Document this variable</span></li>
<li><a name="a313"></a><span class="src-doc">     */    </span></li>
<li><a name="a314"></a>    <span class="src-key">public </span><a href="../PHPonTrax/ActiveRecord.html#var$auto_delete_habtm">$auto_delete_habtm</a> = <span class="src-id">true</span><span class="src-sym">; </span><span class="src-comm"># auto delete $has_and_belongs_to_many associations</span></li>
<li><a name="a315"></a>&nbsp;</li>
<li><a name="a315"></a>    </li>
<li><a name="a316"></a>    <span class="src-doc">/**</span></li>
<li><a name="a317"></a><span class="src-doc">     *  Transactions (only use if your db supports it)</span></li>
<li><a name="a318"></a><span class="src-doc">     *  &lt;b&gt;FIXME: static should be after private&lt;/b&gt;</span></li>
<li><a name="a319"></a><span class="src-doc">     */</span></li>
<li><a name="a320"></a>    <span class="src-key">static </span><span class="src-key">private </span><a href="../PHPonTrax/ActiveRecord.html#var$begin_executed">$begin_executed</a> = <span class="src-id">false</span><span class="src-sym">; </span><span class="src-comm"># this is for transactions only to let query() know that a 'BEGIN' has been executed</span></li>
<li><a name="a321"></a>&nbsp;</li>
<li><a name="a321"></a>    </li>
<li><a name="a322"></a>    <span class="src-doc">/**</span></li>
<li><a name="a323"></a><span class="src-doc">     *  &lt;b&gt;FIXME: static should be after public&lt;/b&gt;</span></li>
<li><a name="a324"></a><span class="src-doc">     */</span></li>
<li><a name="a325"></a>    <span class="src-key">static </span><span class="src-key">public </span><a href="../PHPonTrax/ActiveRecord.html#var$use_transactions">$use_transactions</a> = <span class="src-id">false</span><span class="src-sym">; </span><span class="src-comm"># this will issue a rollback command if any sql fails</span></li>
<li><a name="a326"></a>&nbsp;</li>
<li><a name="a326"></a>    </li>
<li><a name="a327"></a>    <span class="src-doc">/**</span></li>
<li><a name="a328"></a><span class="src-doc">     *  Construct an ActiveRecord object</span></li>
<li><a name="a329"></a><span class="src-doc">     *</span></li>
<li><a name="a330"></a><span class="src-doc">     *  &lt;ol&gt;</span></li>
<li><a name="a331"></a><span class="src-doc">     *    &lt;li&gt;Establish a connection to the database&lt;/li&gt;</span></li>
<li><a name="a332"></a><span class="src-doc">     *    &lt;li&gt;Find the name of the table associated with this object&lt;/li&gt;</span></li>
<li><a name="a333"></a><span class="src-doc">     *    &lt;li&gt;Read description of this table from the database&lt;/li&gt;</span></li>
<li><a name="a334"></a><span class="src-doc">     *    &lt;li&gt;Optionally apply update information to column attributes&lt;/li&gt;</span></li>
<li><a name="a335"></a><span class="src-doc">     *  &lt;/ol&gt;</span></li>
<li><a name="a336"></a><span class="src-doc">     *  </span><span class="src-doc-coretag">@param </span><span class="src-doc-type">string[] </span><span class="src-doc-var">$attributes </span><span class="src-doc">Updates to column attributes</span></li>
<li><a name="a337"></a><span class="src-doc">     *  </span><span class="src-doc-coretag">@uses</span><span class="src-doc"> establish_connection()</span></li>
<li><a name="a338"></a><span class="src-doc">     *  </span><span class="src-doc-coretag">@uses</span><span class="src-doc"> set_content_columns()</span></li>
<li><a name="a339"></a><span class="src-doc">     *  </span><span class="src-doc-coretag">@uses</span><span class="src-doc"> $table_name</span></li>
<li><a name="a340"></a><span class="src-doc">     *  </span><span class="src-doc-coretag">@uses</span><span class="src-doc"> set_table_name_using_class_name()</span></li>
<li><a name="a341"></a><span class="src-doc">     *  </span><span class="src-doc-coretag">@uses</span><span class="src-doc"> update_attributes()</span></li>
<li><a name="a342"></a><span class="src-doc">     */</span></li>
<li><a name="a343"></a>    <span class="src-key">function </span><a href="../PHPonTrax/ActiveRecord.html#method__construct">__construct</a><span class="src-sym">(</span><span class="src-var">$attributes </span>= <span class="src-id">null</span><span class="src-sym">) </span><span class="src-sym">{ </span></li>
<li><a name="a344"></a>        <span class="src-comm"># Open the database connection</span></li>
<li><a name="a345"></a>        <span class="src-var">$this</span><span class="src-sym">-&gt;</span><a href="../PHPonTrax/ActiveRecord.html#methodestablish_connection">establish_connection</a><span class="src-sym">(</span><span class="src-sym">)</span><span class="src-sym">;</span></li>
<li><a name="a346"></a>&nbsp;</li>
<li><a name="a347"></a>        <span class="src-comm"># Set $table_name</span></li>
<li><a name="a348"></a>        <span class="src-key">if</span><span class="src-sym">(</span><span class="src-var">$this</span><span class="src-sym">-&gt;</span><a href="../PHPonTrax/ActiveRecord.html#var$table_name">table_name</a> == <span class="src-id">null</span><span class="src-sym">) </span><span class="src-sym">{</span></li>
<li><a name="a349"></a>            <span class="src-var">$this</span><span class="src-sym">-&gt;</span><a href="../PHPonTrax/ActiveRecord.html#methodset_table_name_using_class_name">set_table_name_using_class_name</a><span class="src-sym">(</span><span class="src-sym">)</span><span class="src-sym">;</span></li>
<li><a name="a350"></a>        <span class="src-sym">}</span></li>
<li><a name="a351"></a>&nbsp;</li>
<li><a name="a352"></a>        <span class="src-comm"># Set column info</span></li>
<li><a name="a353"></a>        <span class="src-key">if</span><span class="src-sym">(</span><span class="src-var">$this</span><span class="src-sym">-&gt;</span><a href="../PHPonTrax/ActiveRecord.html#var$table_name">table_name</a><span class="src-sym">) </span><span class="src-sym">{</span></li>
<li><a name="a354"></a>            <span class="src-var">$this</span><span class="src-sym">-&gt;</span><a href="../PHPonTrax/ActiveRecord.html#methodset_content_columns">set_content_columns</a><span class="src-sym">(</span><span class="src-var">$this</span><span class="src-sym">-&gt;</span><a href="../PHPonTrax/ActiveRecord.html#var$table_name">table_name</a><span class="src-sym">)</span><span class="src-sym">;</span></li>
<li><a name="a355"></a>        <span class="src-sym">}</span></li>
<li><a name="a356"></a>&nbsp;</li>
<li><a name="a357"></a>        <span class="src-comm"># If $attributes array is passed in update the class with its contents</span></li>
<li><a name="a358"></a>        <span class="src-key">if</span><span class="src-sym">(</span><a href="http://www.php.net/is_array">is_array</a><span class="src-sym">(</span><span class="src-var">$attributes</span><span class="src-sym">)) </span><span class="src-sym">{</span></li>
<li><a name="a359"></a>            <span class="src-var">$this</span><span class="src-sym">-&gt;</span><a href="../PHPonTrax/ActiveRecord.html#methodupdate_attributes">update_attributes</a><span class="src-sym">(</span><span class="src-var">$attributes</span><span class="src-sym">)</span><span class="src-sym">;</span></li>
<li><a name="a360"></a>        <span class="src-sym">}</span></li>
<li><a name="a361"></a>    <span class="src-sym">}</span></li>
<li><a name="a362"></a>&nbsp;</li>
<li><a name="a363"></a>    <span class="src-doc">/**</span></li>
<li><a name="a364"></a><span class="src-doc">     *  Override get() if they do $model-&gt;some_association-&gt;field_name</span></li>
<li><a name="a365"></a><span class="src-doc">     *  dynamically load the requested contents from the database.</span></li>
<li><a name="a366"></a><span class="src-doc">     *  </span><span class="src-doc-coretag">@todo</span><span class="src-doc"> Document this API</span></li>
<li><a name="a367"></a><span class="src-doc">     *  </span><span class="src-doc-coretag">@uses</span><span class="src-doc"> $belongs_to</span></li>
<li><a name="a368"></a><span class="src-doc">     *  </span><span class="src-doc-coretag">@uses</span><span class="src-doc"> get_association_type()</span></li>
<li><a name="a369"></a><span class="src-doc">     *  </span><span class="src-doc-coretag">@uses</span><span class="src-doc"> $has_and_belongs_to_many</span></li>
<li><a name="a370"></a><span class="src-doc">     *  </span><span class="src-doc-coretag">@uses</span><span class="src-doc"> $has_many</span></li>
<li><a name="a371"></a><span class="src-doc">     *  </span><span class="src-doc-coretag">@uses</span><span class="src-doc"> $has_one</span></li>
<li><a name="a372"></a><span class="src-doc">     *  </span><span class="src-doc-coretag">@uses</span><span class="src-doc"> find_all_has_many()</span></li>
<li><a name="a373"></a><span class="src-doc">     *  </span><span class="src-doc-coretag">@uses</span><span class="src-doc"> find_all_habtm()</span></li>
<li><a name="a374"></a><span class="src-doc">     *  </span><span class="src-doc-coretag">@uses</span><span class="src-doc"> find_one_belongs_to()</span></li>
<li><a name="a375"></a><span class="src-doc">     *  </span><span class="src-doc-coretag">@uses</span><span class="src-doc"> find_one_has_one()</span></li>
<li><a name="a376"></a><span class="src-doc">     */</span></li>
<li><a name="a377"></a>    <span class="src-key">function </span><a href="../PHPonTrax/ActiveRecord.html#method__get">__get</a><span class="src-sym">(</span><span class="src-var">$key</span><span class="src-sym">) </span><span class="src-sym">{</span></li>
<li><a name="a378"></a>        <span class="src-var">$association_type </span>= <span class="src-var">$this</span><span class="src-sym">-&gt;</span><a href="../PHPonTrax/ActiveRecord.html#methodget_association_type">get_association_type</a><span class="src-sym">(</span><span class="src-var">$key</span><span class="src-sym">)</span><span class="src-sym">;</span></li>
<li><a name="a379"></a>        <span class="src-key">if </span><span class="src-sym">(</span><a href="http://www.php.net/is_null">is_null</a><span class="src-sym">(</span><span class="src-var">$association_type</span><span class="src-sym">)) </span><span class="src-sym">{</span></li>
<li><a name="a380"></a>            <span class="src-key">return </span><span class="src-id">null</span><span class="src-sym">;</span></li>
<li><a name="a381"></a>        <span class="src-sym">}</span></li>
<li><a name="a382"></a>        <span class="src-key">switch</span><span class="src-sym">(</span><span class="src-var">$association_type</span><span class="src-sym">) </span><span class="src-sym">{</span></li>
<li><a name="a383"></a>            <span class="src-key">case </span><span class="src-str">&quot;has_many&quot;</span>:</li>
<li><a name="a384"></a>                <span class="src-var">$parameters </span>= <a href="http://www.php.net/is_array">is_array</a><span class="src-sym">(</span><span class="src-var">$this</span><span class="src-sym">-&gt;</span><a href="../PHPonTrax/ActiveRecord.html#var$has_many">has_many</a><span class="src-sym">) </span>? <span class="src-var">$this</span><span class="src-sym">-&gt;</span><a href="../PHPonTrax/ActiveRecord.html#var$has_many">has_many</a><span class="src-sym">[</span><span class="src-var">$key</span><span class="src-sym">] </span>: <span class="src-id">null</span><span class="src-sym">;</span></li>
<li><a name="a385"></a>                <span class="src-var">$this</span><span class="src-sym">-&gt;</span><span class="src-var">$key </span>= <span class="src-var">$this</span><span class="src-sym">-&gt;</span><a href="../PHPonTrax/ActiveRecord.html#methodfind_all_has_many">find_all_has_many</a><span class="src-sym">(</span><span class="src-var">$key</span><span class="src-sym">, </span><span class="src-var">$parameters</span><span class="src-sym">)</span><span class="src-sym">;</span></li>
<li><a name="a386"></a>                <span class="src-key">break</span><span class="src-sym">;</span></li>
<li><a name="a387"></a>            <span class="src-key">case </span><span class="src-str">&quot;has_one&quot;</span>:</li>
<li><a name="a388"></a>                <span class="src-var">$parameters </span>= <a href="http://www.php.net/is_array">is_array</a><span class="src-sym">(</span><span class="src-var">$this</span><span class="src-sym">-&gt;</span><a href="../PHPonTrax/ActiveRecord.html#var$has_one">has_one</a><span class="src-sym">) </span>? <span class="src-var">$this</span><span class="src-sym">-&gt;</span><a href="../PHPonTrax/ActiveRecord.html#var$has_one">has_one</a><span class="src-sym">[</span><span class="src-var">$key</span><span class="src-sym">] </span>: <span class="src-id">null</span><span class="src-sym">;</span></li>
<li><a name="a389"></a>                <span class="src-var">$this</span><span class="src-sym">-&gt;</span><span class="src-var">$key </span>= <span class="src-var">$this</span><span class="src-sym">-&gt;</span><a href="../PHPonTrax/ActiveRecord.html#methodfind_one_has_one">find_one_has_one</a><span class="src-sym">(</span><span class="src-var">$key</span><span class="src-sym">, </span><span class="src-var">$parameters</span><span class="src-sym">)</span><span class="src-sym">;</span></li>
<li><a name="a390"></a>                <span class="src-key">break</span><span class="src-sym">;</span></li>
<li><a name="a391"></a>            <span class="src-key">case </span><span class="src-str">&quot;belongs_to&quot;</span>:</li>
<li><a name="a392"></a>                <span class="src-var">$parameters </span>= <a href="http://www.php.net/is_array">is_array</a><span class="src-sym">(</span><span class="src-var">$this</span><span class="src-sym">-&gt;</span><a href="../PHPonTrax/ActiveRecord.html#var$belongs_to">belongs_to</a><span class="src-sym">) </span>? <span class="src-var">$this</span><span class="src-sym">-&gt;</span><a href="../PHPonTrax/ActiveRecord.html#var$belongs_to">belongs_to</a><span class="src-sym">[</span><span class="src-var">$key</span><span class="src-sym">] </span>: <span class="src-id">null</span><span class="src-sym">;</span></li>
<li><a name="a393"></a>                <span class="src-var">$this</span><span class="src-sym">-&gt;</span><span class="src-var">$key </span>= <span class="src-var">$this</span><span class="src-sym">-&gt;</span><a href="../PHPonTrax/ActiveRecord.html#methodfind_one_belongs_to">find_one_belongs_to</a><span class="src-sym">(</span><span class="src-var">$key</span><span class="src-sym">, </span><span class="src-var">$parameters</span><span class="src-sym">)</span><span class="src-sym">;</span></li>
<li><a name="a394"></a>                <span class="src-key">break</span><span class="src-sym">;</span></li>
<li><a name="a395"></a>            <span class="src-key">case </span><span class="src-str">&quot;has_and_belongs_to_many&quot;</span>:  </li>
<li><a name="a396"></a>                <span class="src-var">$parameters </span>= <a href="http://www.php.net/is_array">is_array</a><span class="src-sym">(</span><span class="src-var">$this</span><span class="src-sym">-&gt;</span><a href="../PHPonTrax/ActiveRecord.html#var$has_and_belongs_to_many">has_and_belongs_to_many</a><span class="src-sym">) </span>? <span class="src-var">$this</span><span class="src-sym">-&gt;</span><a href="../PHPonTrax/ActiveRecord.html#var$has_and_belongs_to_many">has_and_belongs_to_many</a><span class="src-sym">[</span><span class="src-var">$key</span><span class="src-sym">] </span>: <span class="src-id">null</span><span class="src-sym">;</span></li>
<li><a name="a397"></a>                <span class="src-var">$this</span><span class="src-sym">-&gt;</span><span class="src-var">$key </span>= <span class="src-var">$this</span><span class="src-sym">-&gt;</span><a href="../PHPonTrax/ActiveRecord.html#methodfind_all_habtm">find_all_habtm</a><span class="src-sym">(</span><span class="src-var">$key</span><span class="src-sym">, </span><span class="src-var">$parameters</span><span class="src-sym">)</span><span class="src-sym">; </span></li>
<li><a name="a398"></a>                <span class="src-key">break</span><span class="src-sym">;            </span></li>
<li><a name="a399"></a>        <span class="src-sym">}</span></li>
<li><a name="a400"></a>        <span class="src-comm">//echo &quot;&lt;pre&gt;id: $this-&gt;id&lt;br&gt;getting: $key = &quot;.$this-&gt;$key.&quot;&lt;br&gt;&lt;/pre&gt;&quot;;</span></li>
<li><a name="a401"></a>        <span class="src-key">return </span><span class="src-var">$this</span><span class="src-sym">-&gt;</span><span class="src-var">$key</span><span class="src-sym">;</span></li>
<li><a name="a402"></a>    <span class="src-sym">}</span></li>
<li><a name="a403"></a>&nbsp;</li>
<li><a name="a404"></a>    <span class="src-doc">/**</span></li>
<li><a name="a405"></a><span class="src-doc">     *  Store column value or description of the table format</span></li>
<li><a name="a406"></a><span class="src-doc">     *</span></li>
<li><a name="a407"></a><span class="src-doc">     *  If called with key 'table_name', $value is stored as the</span></li>
<li><a name="a408"></a><span class="src-doc">     *  description of the table format in $content_columns.</span></li>
<li><a name="a409"></a><span class="src-doc">     *  Any other key causes an object variable with the same name to</span></li>
<li><a name="a410"></a><span class="src-doc">     *  be created and stored into.  If the value of $key matches the</span></li>
<li><a name="a411"></a><span class="src-doc">     *  name of a column in content_columns, the corresponding object</span></li>
<li><a name="a412"></a><span class="src-doc">     *  variable becomes the content of the column in this row.</span></li>
<li><a name="a413"></a><span class="src-doc">     *  </span><span class="src-doc-coretag">@uses</span><span class="src-doc"> $auto_save_associations</span></li>
<li><a name="a414"></a><span class="src-doc">     *  </span><span class="src-doc-coretag">@uses</span><span class="src-doc"> get_association_type()</span></li>
<li><a name="a415"></a><span class="src-doc">     *  </span><span class="src-doc-coretag">@uses</span><span class="src-doc"> set_content_columns()</span></li>
<li><a name="a416"></a><span class="src-doc">     */</span></li>
<li><a name="a417"></a>    <span class="src-key">function </span><a href="../PHPonTrax/ActiveRecord.html#method__set">__set</a><span class="src-sym">(</span><span class="src-var">$key</span><span class="src-sym">, </span><span class="src-var">$value</span><span class="src-sym">) </span><span class="src-sym">{</span></li>
<li><a name="a418"></a>        <span class="src-comm">//echo &quot;setting: $key = $value&lt;br&gt;&quot;;</span></li>
<li><a name="a419"></a>        <span class="src-key">if</span><span class="src-sym">(</span><span class="src-var">$key </span>== <span class="src-str">&quot;table_name&quot;</span><span class="src-sym">) </span><span class="src-sym">{</span></li>
<li><a name="a420"></a>            <span class="src-var">$this</span><span class="src-sym">-&gt;</span><a href="../PHPonTrax/ActiveRecord.html#methodset_content_columns">set_content_columns</a><span class="src-sym">(</span><span class="src-var">$value</span><span class="src-sym">)</span><span class="src-sym">;</span></li>
<li><a name="a421"></a>            <span class="src-comm"># this elseif checks if first its an object if its parent is ActiveRecord</span></li>
<li><a name="a422"></a>        <span class="src-sym">} </span><span class="src-key">elseif</span><span class="src-sym">(</span><a href="http://www.php.net/is_object">is_object</a><span class="src-sym">(</span><span class="src-var">$value</span><span class="src-sym">) </span>&amp;&amp; <a href="http://www.php.net/get_parent_class">get_parent_class</a><span class="src-sym">(</span><span class="src-var">$value</span><span class="src-sym">) </span>== __CLASS__ &amp;&amp; <span class="src-var">$this</span><span class="src-sym">-&gt;</span><a href="../PHPonTrax/ActiveRecord.html#var$auto_save_associations">auto_save_associations</a><span class="src-sym">) </span><span class="src-sym">{</span></li>
<li><a name="a423"></a>            <span class="src-key">if</span><span class="src-sym">(</span><span class="src-var">$association_type </span>= <span class="src-var">$this</span><span class="src-sym">-&gt;</span><a href="../PHPonTrax/ActiveRecord.html#methodget_association_type">get_association_type</a><span class="src-sym">(</span><span class="src-var">$key</span><span class="src-sym">)) </span><span class="src-sym">{</span></li>
<li><a name="a424"></a>                <span class="src-var">$this</span><span class="src-sym">-&gt;</span><a href="../PHPonTrax/ActiveRecord.html#var$save_associations">save_associations</a><span class="src-sym">[</span><span class="src-var">$association_type</span><span class="src-sym">]</span><span class="src-sym">[</span><span class="src-sym">] </span>= <span class="src-var">$value</span><span class="src-sym">;</span></li>
<li><a name="a425"></a>                <span class="src-key">if</span><span class="src-sym">(</span><span class="src-var">$association_type </span>== <span class="src-str">&quot;belongs_to&quot;</span><span class="src-sym">) </span><span class="src-sym">{</span></li>
<li><a name="a426"></a>                    <span class="src-var">$foreign_key </span>= <span class="src-id"><a href="../PHPonTrax/Inflector.html">Inflector</a></span><span class="src-sym">::</span><a href="../PHPonTrax/Inflector.html#methodsingularize">singularize</a><span class="src-sym">(</span><span class="src-var">$value</span><span class="src-sym">-&gt;</span><span class="src-id">table_name</span><span class="src-sym">)</span>.<span class="src-str">&quot;_id&quot;</span><span class="src-sym">;</span></li>
<li><a name="a427"></a>                    <span class="src-var">$this</span><span class="src-sym">-&gt;</span><span class="src-var">$foreign_key </span>= <span class="src-var">$value</span><span class="src-sym">-&gt;</span><span class="src-id">id</span><span class="src-sym">; </span></li>
<li><a name="a428"></a>                <span class="src-sym">}</span></li>
<li><a name="a429"></a>            <span class="src-sym">}</span></li>
<li><a name="a430"></a>            <span class="src-comm"># this elseif checks if its an array of objects and if its parent is ActiveRecord                </span></li>
<li><a name="a431"></a>        <span class="src-sym">} </span><span class="src-key">elseif</span><span class="src-sym">(</span><a href="http://www.php.net/is_array">is_array</a><span class="src-sym">(</span><span class="src-var">$value</span><span class="src-sym">) </span>&amp;&amp; <span class="src-var">$this</span><span class="src-sym">-&gt;</span><a href="../PHPonTrax/ActiveRecord.html#var$auto_save_associations">auto_save_associations</a><span class="src-sym">) </span><span class="src-sym">{</span></li>
<li><a name="a432"></a>            <span class="src-key">if</span><span class="src-sym">(</span><span class="src-var">$association_type </span>= <span class="src-var">$this</span><span class="src-sym">-&gt;</span><a href="../PHPonTrax/ActiveRecord.html#methodget_association_type">get_association_type</a><span class="src-sym">(</span><span class="src-var">$key</span><span class="src-sym">)) </span><span class="src-sym">{</span></li>
<li><a name="a433"></a>                <span class="src-var">$this</span><span class="src-sym">-&gt;</span><a href="../PHPonTrax/ActiveRecord.html#var$save_associations">save_associations</a><span class="src-sym">[</span><span class="src-var">$association_type</span><span class="src-sym">]</span><span class="src-sym">[</span><span class="src-sym">] </span>= <span class="src-var">$value</span><span class="src-sym">;</span></li>
<li><a name="a434"></a>            <span class="src-sym">}</span></li>
<li><a name="a435"></a>        <span class="src-sym">}         </span></li>
<li><a name="a436"></a>        </li>
<li><a name="a437"></a>    <span class="src-comm">//  Assignment to something else, do it</span></li>
<li><a name="a438"></a>        <span class="src-var">$this</span><span class="src-sym">-&gt;</span><span class="src-var">$key </span>= <span class="src-var">$value</span><span class="src-sym">;</span></li>
<li><a name="a439"></a>    <span class="src-sym">}</span></li>
<li><a name="a440"></a>&nbsp;</li>
<li><a name="a441"></a>    <span class="src-doc">/**</span></li>
<li><a name="a442"></a><span class="src-doc">     *  Override call() to dynamically call the database associations</span></li>
<li><a name="a443"></a><span class="src-doc">     *  </span><span class="src-doc-coretag">@todo</span><span class="src-doc"> Document this API</span></li>
<li><a name="a444"></a><span class="src-doc">     *  </span><span class="src-doc-coretag">@uses</span><span class="src-doc"> $aggregrations</span></li>
<li><a name="a445"></a><span class="src-doc">     *  </span><span class="src-doc-coretag">@uses</span><span class="src-doc"> aggregrate_all()</span></li>
<li><a name="a446"></a><span class="src-doc">     *  </span><span class="src-doc-coretag">@uses</span><span class="src-doc"> get_association_type()</span></li>
<li><a name="a447"></a><span class="src-doc">     *  </span><span class="src-doc-coretag">@uses</span><span class="src-doc"> $belongs_to</span></li>
<li><a name="a448"></a><span class="src-doc">     *  </span><span class="src-doc-coretag">@uses</span><span class="src-doc"> $has_one</span></li>
<li><a name="a449"></a><span class="src-doc">     *  </span><span class="src-doc-coretag">@uses</span><span class="src-doc"> $has_and_belongs_to_many</span></li>
<li><a name="a450"></a><span class="src-doc">     *  </span><span class="src-doc-coretag">@uses</span><span class="src-doc"> $has_many</span></li>
<li><a name="a451"></a><span class="src-doc">     *  </span><span class="src-doc-coretag">@uses</span><span class="src-doc"> find_all_by()</span></li>
<li><a name="a452"></a><span class="src-doc">     *  </span><span class="src-doc-coretag">@uses</span><span class="src-doc"> find_by()</span></li>
<li><a name="a453"></a><span class="src-doc">     */</span></li>
<li><a name="a454"></a>    <span class="src-key">function </span><a href="../PHPonTrax/ActiveRecord.html#method__call">__call</a><span class="src-sym">(</span><span class="src-var">$method_name</span><span class="src-sym">, </span><span class="src-var">$parameters</span><span class="src-sym">) </span><span class="src-sym">{</span></li>
<li><a name="a455"></a>        <span class="src-key">if</span><span class="src-sym">(</span><a href="http://www.php.net/method_exists">method_exists</a><span class="src-sym">(</span><span class="src-var">$this</span><span class="src-sym">,</span><span class="src-var">$method_name</span><span class="src-sym">)) </span><span class="src-sym">{</span></li>
<li><a name="a456"></a>            <span class="src-comm"># If the method exists, just call it</span></li>
<li><a name="a457"></a>            <span class="src-var">$result </span>= <a href="http://www.php.net/call_user_func">call_user_func</a><span class="src-sym">(</span><span class="src-key">array</span><span class="src-sym">(</span><span class="src-var">$this</span><span class="src-sym">,</span><span class="src-var">$method_name</span><span class="src-sym">)</span><span class="src-sym">, </span><span class="src-var">$parameters</span><span class="src-sym">)</span><span class="src-sym">;</span></li>
<li><a name="a458"></a>        <span class="src-sym">} </span><span class="src-key">else </span><span class="src-sym">{</span></li>
<li><a name="a459"></a>            <span class="src-comm"># ... otherwise, check to see if the method call is one of our</span></li>
<li><a name="a460"></a>            <span class="src-comm"># special Trax methods ...</span></li>
<li><a name="a461"></a>            <span class="src-comm"># ... first check for method names that match any of our explicitly</span></li>
<li><a name="a462"></a>            <span class="src-comm"># declared associations for this model ( e.g. $this-&gt;has_many = array(&quot;movies&quot; =&gt; null) ) ...</span></li>
<li><a name="a463"></a>            <span class="src-var">$association_type </span>= <span class="src-var">$this</span><span class="src-sym">-&gt;</span><a href="../PHPonTrax/ActiveRecord.html#methodget_association_type">get_association_type</a><span class="src-sym">(</span><span class="src-var">$method_name</span><span class="src-sym">)</span><span class="src-sym">;</span></li>
<li><a name="a464"></a>            <span class="src-key">switch</span><span class="src-sym">(</span><span class="src-var">$association_type</span><span class="src-sym">) </span><span class="src-sym">{</span></li>
<li><a name="a465"></a>                <span class="src-key">case </span><span class="src-str">&quot;has_many&quot;</span>:</li>
<li><a name="a466"></a>                    <span class="src-var">$result </span>= <span class="src-var">$this</span><span class="src-sym">-&gt;</span><a href="../PHPonTrax/ActiveRecord.html#methodfind_all_has_many">find_all_has_many</a><span class="src-sym">(</span><span class="src-var">$method_name</span><span class="src-sym">, </span><span class="src-var">$parameters</span><span class="src-sym">)</span><span class="src-sym">;</span></li>
<li><a name="a467"></a>                    <span class="src-key">break</span><span class="src-sym">;</span></li>
<li><a name="a468"></a>                <span class="src-key">case </span><span class="src-str">&quot;has_one&quot;</span>:</li>
<li><a name="a469"></a>                    <span class="src-var">$result </span>= <span class="src-var">$this</span><span class="src-sym">-&gt;</span><a href="../PHPonTrax/ActiveRecord.html#methodfind_one_has_one">find_one_has_one</a><span class="src-sym">(</span><span class="src-var">$method_name</span><span class="src-sym">, </span><span class="src-var">$parameters</span><span class="src-sym">)</span><span class="src-sym">;</span></li>
<li><a name="a470"></a>                    <span class="src-key">break</span><span class="src-sym">;</span></li>
<li><a name="a471"></a>                <span class="src-key">case </span><span class="src-str">&quot;belongs_to&quot;</span>:</li>
<li><a name="a472"></a>                    <span class="src-var">$result </span>= <span class="src-var">$this</span><span class="src-sym">-&gt;</span><a href="../PHPonTrax/ActiveRecord.html#methodfind_one_belongs_to">find_one_belongs_to</a><span class="src-sym">(</span><span class="src-var">$method_name</span><span class="src-sym">, </span><span class="src-var">$parameters</span><span class="src-sym">)</span><span class="src-sym">;</span></li>
<li><a name="a473"></a>                    <span class="src-key">break</span><span class="src-sym">;</span></li>
<li><a name="a474"></a>                <span class="src-key">case </span><span class="src-str">&quot;has_and_belongs_to_many&quot;</span>:  </li>
<li><a name="a475"></a>                    <span class="src-var">$result </span>= <span class="src-var">$this</span><span class="src-sym">-&gt;</span><a href="../PHPonTrax/ActiveRecord.html#methodfind_all_habtm">find_all_habtm</a><span class="src-sym">(</span><span class="src-var">$method_name</span><span class="src-sym">, </span><span class="src-var">$parameters</span><span class="src-sym">)</span><span class="src-sym">; </span></li>
<li><a name="a476"></a>                    <span class="src-key">break</span><span class="src-sym">;            </span></li>
<li><a name="a477"></a>            <span class="src-sym">}</span></li>
<li><a name="a478"></a>&nbsp;</li>
<li><a name="a479"></a>            <span class="src-comm"># check for the [count,sum,avg,etc...]_all magic functions</span></li>
<li><a name="a480"></a>            <span class="src-key">if</span><span class="src-sym">(</span><a href="http://www.php.net/substr">substr</a><span class="src-sym">(</span><span class="src-var">$method_name</span><span class="src-sym">, </span>-<span class="src-num">4</span><span class="src-sym">) </span>== <span class="src-str">&quot;_all&quot; </span>&amp;&amp; <a href="http://www.php.net/in_array">in_array</a><span class="src-sym">(</span><a href="http://www.php.net/substr">substr</a><span class="src-sym">(</span><span class="src-var">$method_name</span><span class="src-sym">, </span><span class="src-num">0</span><span class="src-sym">, </span>-<span class="src-num">4</span><span class="src-sym">)</span><span class="src-sym">,</span><span class="src-var">$this</span><span class="src-sym">-&gt;</span><a href="../PHPonTrax/ActiveRecord.html#var$aggregrations">aggregrations</a><span class="src-sym">)) </span><span class="src-sym">{</span></li>
<li><a name="a481"></a>                <span class="src-comm">//echo &quot;calling method: $method_name&lt;br&gt;&quot;;</span></li>
<li><a name="a482"></a>                <span class="src-var">$result </span>= <span class="src-var">$this</span><span class="src-sym">-&gt;</span><a href="../PHPonTrax/ActiveRecord.html#methodaggregrate_all">aggregrate_all</a><span class="src-sym">(</span><span class="src-var">$method_name</span><span class="src-sym">, </span><span class="src-var">$parameters</span><span class="src-sym">)</span><span class="src-sym">;</span></li>
<li><a name="a483"></a>            <span class="src-sym">}</span></li>
<li><a name="a484"></a>            <span class="src-comm"># check for the find_all_by_* magic functions</span></li>
<li><a name="a485"></a>            <span class="src-key">elseif</span><span class="src-sym">(</span><a href="http://www.php.net/strlen">strlen</a><span class="src-sym">(</span><span class="src-var">$method_name</span><span class="src-sym">) </span>&gt; <span class="src-num">11 </span>&amp;&amp; <a href="http://www.php.net/substr">substr</a><span class="src-sym">(</span><span class="src-var">$method_name</span><span class="src-sym">, </span><span class="src-num">0</span><span class="src-sym">, </span><span class="src-num">11</span><span class="src-sym">) </span>== <span class="src-str">&quot;find_all_by&quot;</span><span class="src-sym">) </span><span class="src-sym">{</span></li>
<li><a name="a486"></a>                <span class="src-comm">//echo &quot;calling method: $method_name&lt;br&gt;&quot;;</span></li>
<li><a name="a487"></a>                <span class="src-var">$result </span>= <span class="src-var">$this</span><span class="src-sym">-&gt;</span><a href="../PHPonTrax/ActiveRecord.html#methodfind_by">find_by</a><span class="src-sym">(</span><span class="src-var">$method_name</span><span class="src-sym">, </span><span class="src-var">$parameters</span><span class="src-sym">, </span><span class="src-id">true</span><span class="src-sym">)</span><span class="src-sym">;</span></li>
<li><a name="a488"></a>            <span class="src-sym">}</span></li>
<li><a name="a489"></a>            <span class="src-comm"># check for the find_by_* magic functions</span></li>
<li><a name="a490"></a>            <span class="src-key">elseif</span><span class="src-sym">(</span><a href="http://www.php.net/strlen">strlen</a><span class="src-sym">(</span><span class="src-var">$method_name</span><span class="src-sym">) </span>&gt; <span class="src-num">7 </span>&amp;&amp; <a href="http://www.php.net/substr">substr</a><span class="src-sym">(</span><span class="src-var">$method_name</span><span class="src-sym">, </span><span class="src-num">0</span><span class="src-sym">, </span><span class="src-num">7</span><span class="src-sym">) </span>== <span class="src-str">&quot;find_by&quot;</span><span class="src-sym">) </span><span class="src-sym">{</span></li>
<li><a name="a491"></a>                <span class="src-comm">//echo &quot;calling method: $method_name&lt;br&gt;&quot;;</span></li>
<li><a name="a492"></a>                <span class="src-var">$result </span>= <span class="src-var">$this</span><span class="src-sym">-&gt;</span><a href="../PHPonTrax/ActiveRecord.html#methodfind_by">find_by</a><span class="src-sym">(</span><span class="src-var">$method_name</span><span class="src-sym">, </span><span class="src-var">$parameters</span><span class="src-sym">)</span><span class="src-sym">;</span></li>
<li><a name="a493"></a>            <span class="src-sym">}</span></li>
<li><a name="a494"></a>        <span class="src-sym">}</span></li>
<li><a name="a495"></a>        <span class="src-key">return </span><span class="src-var">$result</span><span class="src-sym">;</span></li>
<li><a name="a496"></a>    <span class="src-sym">}</span></li>
<li><a name="a497"></a>&nbsp;</li>
<li><a name="a498"></a>    <span class="src-doc">/**</span></li>
<li><a name="a499"></a><span class="src-doc">     *  Returns a the name of the join table that would be used for the two</span></li>
<li><a name="a500"></a><span class="src-doc">     *  tables.  The join table name is decided from the alphabetical order</span></li>
<li><a name="a501"></a><span class="src-doc">     *  of the two tables.  e.g. &quot;genres_movies&quot; because &quot;g&quot; comes before &quot;m&quot;</span></li>
<li><a name="a502"></a><span class="src-doc">     *</span></li>
<li><a name="a503"></a><span class="src-doc">     *  Parameters: $first_table, $second_table: the names of two database tables,</span></li>
<li><a name="a504"></a><span class="src-doc">     *   e.g. &quot;movies&quot; and &quot;genres&quot;</span></li>
<li><a name="a505"></a><span class="src-doc">     *  </span><span class="src-doc-coretag">@todo</span><span class="src-doc"> Document this API</span></li>
<li><a name="a506"></a><span class="src-doc">     */</span></li>
<li><a name="a507"></a>    <span class="src-key">private </span><span class="src-key">function </span><a href="../PHPonTrax/ActiveRecord.html#methodget_join_table_name">get_join_table_name</a><span class="src-sym">(</span><span class="src-var">$first_table</span><span class="src-sym">, </span><span class="src-var">$second_table</span><span class="src-sym">) </span><span class="src-sym">{</span></li>
<li><a name="a508"></a>        <span class="src-var">$tables </span>= <span class="src-key">array</span><span class="src-sym">(</span><span class="src-sym">)</span><span class="src-sym">;</span></li>
<li><a name="a509"></a>        <span class="src-var">$tables</span><span class="src-sym">[</span><span class="src-str">&quot;one&quot;</span><span class="src-sym">] </span>= <span class="src-var">$first_table</span><span class="src-sym">;</span></li>
<li><a name="a510"></a>        <span class="src-var">$tables</span><span class="src-sym">[</span><span class="src-str">&quot;many&quot;</span><span class="src-sym">] </span>= <span class="src-var">$second_table</span><span class="src-sym">;</span></li>
<li><a name="a511"></a>        <span class="src-sym">@</span><a href="http://www.php.net/asort">asort</a><span class="src-sym">(</span><span class="src-var">$tables</span><span class="src-sym">)</span><span class="src-sym">;</span></li>
<li><a name="a512"></a>        <span class="src-key">return </span><span class="src-sym">@</span><a href="http://www.php.net/implode">implode</a><span class="src-sym">(</span><span class="src-str">&quot;_&quot;</span><span class="src-sym">, </span><span class="src-var">$tables</span><span class="src-sym">)</span><span class="src-sym">;</span></li>
<li><a name="a513"></a>    <span class="src-sym">}</span></li>
<li><a name="a514"></a>&nbsp;</li>
<li><a name="a515"></a>    <span class="src-doc">/**</span></li>
<li><a name="a516"></a><span class="src-doc">     *  Find all records using a &quot;has_and_belongs_to_many&quot; relationship</span></li>
<li><a name="a517"></a><span class="src-doc">     * (many-to-many with a join table in between).  Note that you can also</span></li>
<li><a name="a518"></a><span class="src-doc">     *  specify an optional &quot;paging limit&quot; by setting the corresponding &quot;limit&quot;</span></li>
<li><a name="a519"></a><span class="src-doc">     *  instance variable.  For example, if you want to return 10 movies from the</span></li>
<li><a name="a520"></a><span class="src-doc">     *  5th movie on, you could set $this-&gt;movies_limit = &quot;10, 5&quot;</span></li>
<li><a name="a521"></a><span class="src-doc">     *</span></li>
<li><a name="a522"></a><span class="src-doc">     *  Parameters: $this_table_name:  The name of the database table that has the</span></li>
<li><a name="a523"></a><span class="src-doc">     *                                 one row you are interested in.  E.g. genres</span></li>
<li><a name="a524"></a><span class="src-doc">     *              $other_table_name: The name of the database table that has the</span></li>
<li><a name="a525"></a><span class="src-doc">     *                                 many rows you are interested in.  E.g. movies</span></li>
<li><a name="a526"></a><span class="src-doc">     *  Returns: An array of ActiveRecord objects. (e.g. Movie objects)</span></li>
<li><a name="a527"></a><span class="src-doc">     *  </span><span class="src-doc-coretag">@todo</span><span class="src-doc"> Document this API</span></li>
<li><a name="a528"></a><span class="src-doc">     */</span></li>
<li><a name="a529"></a>    <span class="src-key">private </span><span class="src-key">function </span><a href="../PHPonTrax/ActiveRecord.html#methodfind_all_habtm">find_all_habtm</a><span class="src-sym">(</span><span class="src-var">$other_table_name</span><span class="src-sym">, </span><span class="src-var">$parameters </span>= <span class="src-id">null</span><span class="src-sym">) </span><span class="src-sym">{</span></li>
<li><a name="a530"></a>        <span class="src-var">$other_class_name </span>= <span class="src-id"><a href="../PHPonTrax/Inflector.html">Inflector</a></span><span class="src-sym">::</span><a href="../PHPonTrax/Inflector.html#methodclassify">classify</a><span class="src-sym">(</span><span class="src-var">$other_table_name</span><span class="src-sym">)</span><span class="src-sym">;</span></li>
<li><a name="a531"></a>        <span class="src-comm"># Instantiate an object to access find_all</span></li>
<li><a name="a532"></a>        <span class="src-var">$results </span>= <span class="src-key">new </span><span class="src-var">$other_class_name</span><span class="src-sym">(</span><span class="src-sym">)</span><span class="src-sym">;</span></li>
<li><a name="a533"></a>&nbsp;</li>
<li><a name="a534"></a>        <span class="src-comm"># Prepare the join table name primary keys (fields) to do the join on</span></li>
<li><a name="a535"></a>        <span class="src-var">$join_table </span>= <span class="src-var">$this</span><span class="src-sym">-&gt;</span><a href="../PHPonTrax/ActiveRecord.html#methodget_join_table_name">get_join_table_name</a><span class="src-sym">(</span><span class="src-var">$this</span><span class="src-sym">-&gt;</span><a href="../PHPonTrax/ActiveRecord.html#var$table_name">table_name</a><span class="src-sym">, </span><span class="src-var">$other_table_name</span><span class="src-sym">)</span><span class="src-sym">;</span></li>
<li><a name="a536"></a>        <span class="src-var">$this_foreign_key </span>= <span class="src-id"><a href="../PHPonTrax/Inflector.html">Inflector</a></span><span class="src-sym">::</span><a href="../PHPonTrax/Inflector.html#methodsingularize">singularize</a><span class="src-sym">(</span><span class="src-var">$this</span><span class="src-sym">-&gt;</span><a href="../PHPonTrax/ActiveRecord.html#var$table_name">table_name</a><span class="src-sym">)</span>.<span class="src-str">&quot;_id&quot;</span><span class="src-sym">;</span></li>
<li><a name="a537"></a>        <span class="src-var">$other_foreign_key </span>= <span class="src-id"><a href="../PHPonTrax/Inflector.html">Inflector</a></span><span class="src-sym">::</span><a href="../PHPonTrax/Inflector.html#methodsingularize">singularize</a><span class="src-sym">(</span><span class="src-var">$other_table_name</span><span class="src-sym">)</span>.<span class="src-str">&quot;_id&quot;</span><span class="src-sym">;</span></li>
<li><a name="a538"></a>        <span class="src-comm"># Set up the SQL segments</span></li>
<li><a name="a539"></a>        <span class="src-var">$conditions </span>= <span class="src-str">&quot;</span>{<span class="src-var">$join_table<span class="src-str"></span><span class="src-sym">}</span>.{<span class="src-var">$this_foreign_key</span><span class="src-sym">}</span>=</span><span class="src-str">&quot;</span>.<a href="http://www.php.net/intval">intval</a><span class="src-sym">(</span><span class="src-var">$this</span><span class="src-sym">-&gt;</span><span class="src-var">id</span><span class="src-sym">)</span><span class="src-sym">;</span></li>
<li><a name="a540"></a>        <span class="src-var">$orderings </span>= <span class="src-id">null</span><span class="src-sym">;</span></li>
<li><a name="a541"></a>        <span class="src-var">$limit </span>= <span class="src-id">null</span><span class="src-sym">;</span></li>
<li><a name="a542"></a>        <span class="src-var">$joins </span>= <span class="src-str">&quot;</span><span class="src-str"><span class="src-id">LEFT</span> <span class="src-id">JOIN</span> {<span class="src-var">$join_table</span><span class="src-sym">}</span> <span class="src-id">ON</span> {<span class="src-var">$other_table_name</span><span class="src-sym">}</span>.<span class="src-id">id</span> = {<span class="src-var">$other_foreign_key</span><span class="src-sym">}</span></span><span class="src-str">&quot;</span><span class="src-sym">;</span></li>
<li><a name="a543"></a>&nbsp;</li>
<li><a name="a544"></a>        <span class="src-comm"># Use any passed-in parameters</span></li>
<li><a name="a545"></a>        <span class="src-key">if </span><span class="src-sym">(</span><span class="src-sym">!</span><a href="http://www.php.net/is_null">is_null</a><span class="src-sym">(</span><span class="src-var">$parameters</span><span class="src-sym">)) </span><span class="src-sym">{</span></li>
<li><a name="a546"></a>            <span class="src-key">if</span><span class="src-sym">(</span><span class="src-sym">@</span><a href="http://www.php.net/array_key_exists">array_key_exists</a><span class="src-sym">(</span><span class="src-str">&quot;conditions&quot;</span><span class="src-sym">, </span><span class="src-var">$parameters</span><span class="src-sym">))</span></li>
<li><a name="a547"></a>                <span class="src-var">$additional_conditions </span>= <span class="src-var">$parameters</span><span class="src-sym">[</span><span class="src-str">'conditions'</span><span class="src-sym">]</span><span class="src-sym">;</span></li>
<li><a name="a548"></a>            <span class="src-key">elseif</span><span class="src-sym">(</span><span class="src-var">$parameters</span><span class="src-sym">[</span><span class="src-num">0</span><span class="src-sym">] </span>!= <span class="src-str">&quot;&quot;</span><span class="src-sym">)</span></li>
<li><a name="a549"></a>                <span class="src-var">$additional_conditions </span>= <span class="src-var">$parameters</span><span class="src-sym">[</span><span class="src-num">0</span><span class="src-sym">]</span><span class="src-sym">;</span></li>
<li><a name="a550"></a>&nbsp;</li>
<li><a name="a551"></a>            <span class="src-key">if</span><span class="src-sym">(</span><span class="src-sym">@</span><a href="http://www.php.net/array_key_exists">array_key_exists</a><span class="src-sym">(</span><span class="src-str">&quot;orderings&quot;</span><span class="src-sym">, </span><span class="src-var">$parameters</span><span class="src-sym">))</span></li>
<li><a name="a552"></a>                <span class="src-var">$orderings </span>= <span class="src-var">$parameters</span><span class="src-sym">[</span><span class="src-str">'orderings'</span><span class="src-sym">]</span><span class="src-sym">;</span></li>
<li><a name="a553"></a>            <span class="src-key">elseif</span><span class="src-sym">(</span><span class="src-var">$parameters</span><span class="src-sym">[</span><span class="src-num">1</span><span class="src-sym">] </span>!= <span class="src-str">&quot;&quot;</span><span class="src-sym">)</span></li>
<li><a name="a554"></a>                <span class="src-var">$orderings </span>= <span class="src-var">$parameters</span><span class="src-sym">[</span><span class="src-num">1</span><span class="src-sym">]</span><span class="src-sym">;</span></li>
<li><a name="a555"></a>&nbsp;</li>
<li><a name="a556"></a>            <span class="src-key">if</span><span class="src-sym">(</span><span class="src-sym">@</span><a href="http://www.php.net/array_key_exists">array_key_exists</a><span class="src-sym">(</span><span class="src-str">&quot;limit&quot;</span><span class="src-sym">, </span><span class="src-var">$parameters</span><span class="src-sym">))</span></li>
<li><a name="a557"></a>                <span class="src-var">$limit </span>= <span class="src-var">$parameters</span><span class="src-sym">[</span><span class="src-str">'limit'</span><span class="src-sym">]</span><span class="src-sym">;</span></li>
<li><a name="a558"></a>            <span class="src-key">elseif</span><span class="src-sym">(</span><span class="src-var">$parameters</span><span class="src-sym">[</span><span class="src-num">2</span><span class="src-sym">] </span>!= <span class="src-str">&quot;&quot;</span><span class="src-sym">)</span></li>
<li><a name="a559"></a>                <span class="src-var">$limit </span>= <span class="src-var">$parameters</span><span class="src-sym">[</span><span class="src-num">2</span><span class="src-sym">]</span><span class="src-sym">;</span></li>
<li><a name="a560"></a>&nbsp;</li>
<li><a name="a561"></a>            <span class="src-key">if</span><span class="src-sym">(</span><span class="src-sym">@</span><a href="http://www.php.net/array_key_exists">array_key_exists</a><span class="src-sym">(</span><span class="src-str">&quot;joins&quot;</span><span class="src-sym">, </span><span class="src-var">$parameters</span><span class="src-sym">))</span></li>
<li><a name="a562"></a>                <span class="src-var">$additional_joins </span>= <span class="src-var">$parameters</span><span class="src-sym">[</span><span class="src-str">'joins'</span><span class="src-sym">]</span><span class="src-sym">;</span></li>
<li><a name="a563"></a>            <span class="src-key">elseif</span><span class="src-sym">(</span><span class="src-var">$parameters</span><span class="src-sym">[</span><span class="src-num">3</span><span class="src-sym">] </span>!= <span class="src-str">&quot;&quot;</span><span class="src-sym">)</span></li>
<li><a name="a564"></a>                <span class="src-var">$additional_joins </span>= <span class="src-var">$parameters</span><span class="src-sym">[</span><span class="src-num">3</span><span class="src-sym">]</span><span class="src-sym">;</span></li>
<li><a name="a565"></a>&nbsp;</li>
<li><a name="a566"></a>            <span class="src-key">if </span><span class="src-sym">(</span><span class="src-sym">!</span><span class="src-key">empty</span><span class="src-sym">(</span><span class="src-var">$additional_conditions</span><span class="src-sym">))</span></li>
<li><a name="a567"></a>                <span class="src-var">$conditions </span>.= <span class="src-str">&quot; AND (&quot; </span>. <span class="src-var">$additional_conditions </span>. <span class="src-str">&quot;)&quot;</span><span class="src-sym">;</span></li>
<li><a name="a568"></a>            <span class="src-key">if </span><span class="src-sym">(</span><span class="src-sym">!</span><span class="src-key">empty</span><span class="src-sym">(</span><span class="src-var">$additional_joins</span><span class="src-sym">))</span></li>
<li><a name="a569"></a>                <span class="src-var">$joins </span>.= <span class="src-str">&quot; &quot; </span>. <span class="src-var">$additional_joins</span><span class="src-sym">;</span></li>
<li><a name="a570"></a>        <span class="src-sym">}</span></li>
<li><a name="a571"></a>&nbsp;</li>
<li><a name="a572"></a>        <span class="src-comm"># Get the list of other_class_name objects</span></li>
<li><a name="a573"></a>        <span class="src-key">return </span><span class="src-var">$results</span><span class="src-sym">-&gt;</span><span class="src-id">find_all</span><span class="src-sym">(</span><span class="src-var">$conditions</span><span class="src-sym">, </span><span class="src-var">$orderings</span><span class="src-sym">, </span><span class="src-var">$limit</span><span class="src-sym">, </span><span class="src-var">$joins</span><span class="src-sym">)</span><span class="src-sym">;</span></li>
<li><a name="a574"></a>    <span class="src-sym">}</span></li>
<li><a name="a575"></a>&nbsp;</li>
<li><a name="a576"></a>    <span class="src-doc">/**</span></li>
<li><a name="a577"></a><span class="src-doc">     *  Find all records using a &quot;has_many&quot; relationship (one-to-many)</span></li>
<li><a name="a578"></a><span class="src-doc">     *</span></li>
<li><a name="a579"></a><span class="src-doc">     *  Parameters: $other_table_name: The name of the other table that contains</span></li>
<li><a name="a580"></a><span class="src-doc">     *                                 many rows relating to this object's id.</span></li>
<li><a name="a581"></a><span class="src-doc">     *  Returns: An array of ActiveRecord objects. (e.g. Contact objects)</span></li>
<li><a name="a582"></a><span class="src-doc">     *  </span><span class="src-doc-coretag">@todo</span><span class="src-doc"> Document this API</span></li>
<li><a name="a583"></a><span class="src-doc">     */</span></li>
<li><a name="a584"></a>    <span class="src-key">private </span><span class="src-key">function </span><a href="../PHPonTrax/ActiveRecord.html#methodfind_all_has_many">find_all_has_many</a><span class="src-sym">(</span><span class="src-var">$other_table_name</span><span class="src-sym">, </span><span class="src-var">$parameters </span>= <span class="src-id">null</span><span class="src-sym">) </span><span class="src-sym">{</span></li>
<li><a name="a585"></a>        <span class="src-comm"># Prepare the class name and primary key, e.g. if</span></li>
<li><a name="a586"></a>        <span class="src-comm"># customers has_many contacts, then we'll need a Contact</span></li>
<li><a name="a587"></a>        <span class="src-comm"># object, and the customer_id field name.</span></li>
<li><a name="a588"></a>        <span class="src-key">if</span><span class="src-sym">(</span><span class="src-sym">@</span><a href="http://www.php.net/array_key_exists">array_key_exists</a><span class="src-sym">(</span><span class="src-str">&quot;foreign_key&quot;</span><span class="src-sym">, </span><span class="src-var">$parameters</span><span class="src-sym">))</span></li>
<li><a name="a589"></a>            <span class="src-var">$foreign_key </span>= <span class="src-var">$parameters</span><span class="src-sym">[</span><span class="src-str">'foreign_key'</span><span class="src-sym">]</span><span class="src-sym">;</span></li>
<li><a name="a590"></a>        <span class="src-key">else</span></li>
<li><a name="a591"></a>            <span class="src-var">$foreign_key </span>= <span class="src-id"><a href="../PHPonTrax/Inflector.html">Inflector</a></span><span class="src-sym">::</span><a href="../PHPonTrax/Inflector.html#methodsingularize">singularize</a><span class="src-sym">(</span><span class="src-var">$this</span><span class="src-sym">-&gt;</span><a href="../PHPonTrax/ActiveRecord.html#var$table_name">table_name</a><span class="src-sym">)</span>.<span class="src-str">&quot;_id&quot;</span><span class="src-sym">;</span></li>
<li><a name="a592"></a>&nbsp;</li>
<li><a name="a593"></a>        <span class="src-var">$other_class_name </span>= <span class="src-id"><a href="../PHPonTrax/Inflector.html">Inflector</a></span><span class="src-sym">::</span><a href="../PHPonTrax/Inflector.html#methodclassify">classify</a><span class="src-sym">(</span><span class="src-var">$other_table_name</span><span class="src-sym">)</span><span class="src-sym">;</span></li>
<li><a name="a594"></a>        <span class="src-var">$conditions </span>= <span class="src-str">&quot;</span>{<span class="src-var">$foreign_key</span><span class="src-str"></span><span class="src-sym">}</span>=<span class="src-var">$this</span><span class="src-sym">-&gt;</span><span class="src-var">id</span><span class="src-str">"</span></span><span class="src-sym">;</span></li>
<li><a name="a595"></a>&nbsp;</li>
<li><a name="a596"></a>        <span class="src-comm"># Use any passed-in parameters</span></li>
<li><a name="a597"></a>        <span class="src-key">if </span><span class="src-sym">(</span><span class="src-sym">!</span><a href="http://www.php.net/is_null">is_null</a><span class="src-sym">(</span><span class="src-var">$parameters</span><span class="src-sym">)) </span><span class="src-sym">{</span></li>
<li><a name="a598"></a>            <span class="src-comm">//echo &quot;&lt;pre&gt;&quot;;print_r($parameters);</span></li>
<li><a name="a599"></a>            <span class="src-key">if</span><span class="src-sym">(</span><span class="src-sym">@</span><a href="http://www.php.net/array_key_exists">array_key_exists</a><span class="src-sym">(</span><span class="src-str">&quot;conditions&quot;</span><span class="src-sym">, </span><span class="src-var">$parameters</span><span class="src-sym">))</span></li>
<li><a name="a600"></a>                <span class="src-var">$additional_conditions </span>= <span class="src-var">$parameters</span><span class="src-sym">[</span><span class="src-str">'conditions'</span><span class="src-sym">]</span><span class="src-sym">;</span></li>
<li><a name="a601"></a>            <span class="src-key">elseif</span><span class="src-sym">(</span><span class="src-var">$parameters</span><span class="src-sym">[</span><span class="src-num">0</span><span class="src-sym">] </span>!= <span class="src-str">&quot;&quot;</span><span class="src-sym">)</span></li>
<li><a name="a602"></a>                <span class="src-var">$additional_conditions </span>= <span class="src-var">$parameters</span><span class="src-sym">[</span><span class="src-num">0</span><span class="src-sym">]</span><span class="src-sym">;</span></li>
<li><a name="a603"></a>&nbsp;</li>
<li><a name="a604"></a>            <span class="src-key">if</span><span class="src-sym">(</span><span class="src-sym">@</span><a href="http://www.php.net/array_key_exists">array_key_exists</a><span class="src-sym">(</span><span class="src-str">&quot;orderings&quot;</span><span class="src-sym">, </span><span class="src-var">$parameters</span><span class="src-sym">))</span></li>
<li><a name="a605"></a>                <span class="src-var">$orderings </span>= <span class="src-var">$parameters</span><span class="src-sym">[</span><span class="src-str">'orderings'</span><span class="src-sym">]</span><span class="src-sym">;</span></li>
<li><a name="a606"></a>            <span class="src-key">elseif</span><span class="src-sym">(</span><span class="src-var">$parameters</span><span class="src-sym">[</span><span class="src-num">1</span><span class="src-sym">] </span>!= <span class="src-str">&quot;&quot;</span><span class="src-sym">)</span></li>
<li><a name="a607"></a>                <span class="src-var">$orderings </span>= <span class="src-var">$parameters</span><span class="src-sym">[</span><span class="src-num">1</span><span class="src-sym">]</span><span class="src-sym">;</span></li>
<li><a name="a608"></a>&nbsp;</li>
<li><a name="a609"></a>            <span class="src-key">if</span><span class="src-sym">(</span><span class="src-sym">@</span><a href="http://www.php.net/array_key_exists">array_key_exists</a><span class="src-sym">(</span><span class="src-str">&quot;limit&quot;</span><span class="src-sym">, </span><span class="src-var">$parameters</span><span class="src-sym">))</span></li>
<li><a name="a610"></a>                <span class="src-var">$limit </span>= <span class="src-var">$parameters</span><span class="src-sym">[</span><span class="src-str">'limit'</span><span class="src-sym">]</span><span class="src-sym">;</span></li>
<li><a name="a611"></a>            <span class="src-key">elseif</span><span class="src-sym">(</span><span class="src-var">$parameters</span><span class="src-sym">[</span><span class="src-num">2</span><span class="src-sym">] </span>!= <span class="src-str">&quot;&quot;</span><span class="src-sym">)</span></li>
<li><a name="a612"></a>                <span class="src-var">$limit </span>= <span class="src-var">$parameters</span><span class="src-sym">[</span><span class="src-num">2</span><span class="src-sym">]</span><span class="src-sym">;</span></li>
<li><a name="a613"></a>&nbsp;</li>
<li><a name="a614"></a>            <span class="src-key">if</span><span class="src-sym">(</span><span class="src-sym">@</span><a href="http://www.php.net/array_key_exists">array_key_exists</a><span class="src-sym">(</span><span class="src-str">&quot;joins&quot;</span><span class="src-sym">, </span><span class="src-var">$parameters</span><span class="src-sym">))</span></li>
<li><a name="a615"></a>                <span class="src-var">$additional_joins </span>= <span class="src-var">$parameters</span><span class="src-sym">[</span><span class="src-str">'joins'</span><span class="src-sym">]</span><span class="src-sym">;</span></li>
<li><a name="a616"></a>            <span class="src-key">elseif</span><span class="src-sym">(</span><span class="src-var">$parameters</span><span class="src-sym">[</span><span class="src-num">3</span><span class="src-sym">] </span>!= <span class="src-str">&quot;&quot;</span><span class="src-sym">)</span></li>
<li><a name="a617"></a>                <span class="src-var">$additional_joins </span>= <span class="src-var">$parameters</span><span class="src-sym">[</span><span class="src-num">3</span><span class="src-sym">]</span><span class="src-sym">;</span></li>
<li><a name="a618"></a>&nbsp;</li>
<li><a name="a619"></a>            <span class="src-key">if</span><span class="src-sym">(</span><span class="src-sym">!</span><span class="src-key">empty</span><span class="src-sym">(</span><span class="src-var">$additional_conditions</span><span class="src-sym">))</span></li>
<li><a name="a620"></a>                <span class="src-var">$conditions </span>.= <span class="src-str">&quot; AND (&quot; </span>. <span class="src-var">$additional_conditions </span>. <span class="src-str">&quot;)&quot;</span><span class="src-sym">;</span></li>
<li><a name="a621"></a>            <span class="src-key">if</span><span class="src-sym">(</span><span class="src-sym">!</span><span class="src-key">empty</span><span class="src-sym">(</span><span class="src-var">$additional_joins</span><span class="src-sym">))</span></li>
<li><a name="a622"></a>                <span class="src-var">$joins </span>.= <span class="src-str">&quot; &quot; </span>. <span class="src-var">$additional_joins</span><span class="src-sym">;</span></li>
<li><a name="a623"></a>        <span class="src-sym">}</span></li>
<li><a name="a624"></a>&nbsp;</li>
<li><a name="a625"></a>        <span class="src-comm"># Instantiate an object to access find_all</span></li>
<li><a name="a626"></a>        <span class="src-var">$other_class_object </span>= <span class="src-key">new </span><span class="src-var">$other_class_name</span><span class="src-sym">(</span><span class="src-sym">)</span><span class="src-sym">;</span></li>
<li><a name="a627"></a>        <span class="src-comm"># Get the list of other_class_name objects</span></li>
<li><a name="a628"></a>        <span class="src-var">$results </span>= <span class="src-var">$other_class_object</span><span class="src-sym">-&gt;</span><span class="src-id">find_all</span><span class="src-sym">(</span><span class="src-var">$conditions</span><span class="src-sym">, </span><span class="src-var">$orderings</span><span class="src-sym">, </span><span class="src-var">$limit</span><span class="src-sym">, </span><span class="src-var">$joins</span><span class="src-sym">)</span><span class="src-sym">;</span></li>
<li><a name="a629"></a>&nbsp;</li>
<li><a name="a630"></a>        <span class="src-key">return </span><span class="src-var">$results</span><span class="src-sym">;</span></li>
<li><a name="a631"></a>    <span class="src-sym">}</span></li>
<li><a name="a632"></a>&nbsp;</li>
<li><a name="a633"></a>    <span class="src-doc">/**</span></li>
<li><a name="a634"></a><span class="src-doc">     *  Find all records using a &quot;has_one&quot; relationship (one-to-one)</span></li>
<li><a name="a635"></a><span class="src-doc">     *  (the foreign key being in the other table)</span></li>
<li><a name="a636"></a><span class="src-doc">     *  Parameters: $other_table_name: The name of the other table that contains</span></li>
<li><a name="a637"></a><span class="src-doc">     *                                 many rows relating to this object's id.</span></li>
<li><a name="a638"></a><span class="src-doc">     *  Returns: An array of ActiveRecord objects. (e.g. Contact objects)</span></li>
<li><a name="a639"></a><span class="src-doc">     *  </span><span class="src-doc-coretag">@todo</span><span class="src-doc"> Document this API</span></li>
<li><a name="a640"></a><span class="src-doc">     */</span></li>
<li><a name="a641"></a>    <span class="src-key">private </span><span class="src-key">function </span><a href="../PHPonTrax/ActiveRecord.html#methodfind_one_has_one">find_one_has_one</a><span class="src-sym">(</span><span class="src-var">$other_object_name</span><span class="src-sym">, </span><span class="src-var">$parameters </span>= <span class="src-id">null</span><span class="src-sym">) </span><span class="src-sym">{</span></li>
<li><a name="a642"></a>        <span class="src-comm"># Prepare the class name and primary key, e.g. if</span></li>
<li><a name="a643"></a>        <span class="src-comm"># customers has_many contacts, then we'll need a Contact</span></li>
<li><a name="a644"></a>        <span class="src-comm"># object, and the customer_id field name.</span></li>
<li><a name="a645"></a>        <span class="src-var">$other_class_name </span>= <span class="src-id"><a href="../PHPonTrax/Inflector.html">Inflector</a></span><span class="src-sym">::</span><a href="../PHPonTrax/Inflector.html#methodcamelize">camelize</a><span class="src-sym">(</span><span class="src-var">$other_object_name</span><span class="src-sym">)</span><span class="src-sym">;</span></li>
<li><a name="a646"></a>        <span class="src-key">if</span><span class="src-sym">(</span><span class="src-sym">@</span><a href="http://www.php.net/array_key_exists">array_key_exists</a><span class="src-sym">(</span><span class="src-str">&quot;foreign_key&quot;</span><span class="src-sym">, </span><span class="src-var">$parameters</span><span class="src-sym">))</span></li>
<li><a name="a647"></a>            <span class="src-var">$foreign_key </span>= <span class="src-var">$parameters</span><span class="src-sym">[</span><span class="src-str">'foreign_key'</span><span class="src-sym">]</span><span class="src-sym">;</span></li>
<li><a name="a648"></a>        <span class="src-key">else</span></li>
<li><a name="a649"></a>            <span class="src-var">$foreign_key </span>= <span class="src-id"><a href="../PHPonTrax/Inflector.html">Inflector</a></span><span class="src-sym">::</span><a href="../PHPonTrax/Inflector.html#methodsingularize">singularize</a><span class="src-sym">(</span><span class="src-var">$this</span><span class="src-sym">-&gt;</span><a href="../PHPonTrax/ActiveRecord.html#var$table_name">table_name</a><span class="src-sym">)</span>.<span class="src-str">&quot;_id&quot;</span><span class="src-sym">;</span></li>
<li><a name="a650"></a>&nbsp;</li>
<li><a name="a651"></a>        <span class="src-var">$conditions </span>= <span class="src-str">&quot;</span><span class="src-str"><span class="src-var">$foreign_key</span>='{<span class="src-var">$this</span></span><span class="src-sym">-&gt;</span><span class="src-var">id</span><span class="src-sym">}</span>'</span><span class="src-str"><span class="src-str">"</span><span class="src-sym">;</span></span></li>
<li><a name="a652"></a></span><span class="src-str">        <span class="src-comm"># Instantiate an object to access find_all</span></span></li>
<li><a name="a653"></a></span><span class="src-str"><span class="src-comm"></span>        <span class="src-var">$results</span> = <span class="src-key">new</span> <span class="src-var">$other_class_name</span><span class="src-sym">(</span><span class="src-sym">)</span><span class="src-sym">;</span></span></li>
<li><a name="a654"></a></span><span class="src-str">        <span class="src-comm"># Get the list of other_class_name objects</span></span></li>
<li><a name="a655"></a></span><span class="src-str"><span class="src-comm"></span>        <span class="src-var">$results</span> = <span class="src-var">$results</span></span><span class="src-sym">-&gt;</span><span class="src-id">find_first</span><span class="src-sym">(</span><span class="src-var">$conditions</span><span class="src-sym">, </span><span class="src-var">$orderings</span><span class="src-sym">)</span><span class="src-sym">;</span></li>
<li><a name="a656"></a>        <span class="src-comm"># There should only be one result, an object, if so return it</span></li>
<li><a name="a657"></a>        <span class="src-key">if</span><span class="src-sym">(</span><span class="src-id">is_object</span><span class="src-sym">(</span><span class="src-var">$results</span><span class="src-sym">)) </span><span class="src-str"></span><span class="src-sym">{</span></span></li>
<li><a name="a658"></a></span><span class="src-str">            <span class="src-key">return</span> <span class="src-var">$results</span><span class="src-sym">;</span></span></li>
<li><a name="a659"></a></span><span class="src-str">        <span class="src-sym">}</span> <span class="src-key">else</span> <span class="src-sym">{</span></span></li>
<li><a name="a660"></a></span><span class="src-str">            <span class="src-key">return</span> <span class="src-id">null</span><span class="src-sym">;</span></span></li>
<li><a name="a661"></a></span><span class="src-str">        <span class="src-sym">}</span></span></li>
<li><a name="a662"></a></span><span class="src-str">    <span class="src-sym">}</span></span></li>
<li><a name="a663"></a>&nbsp;</li>
<li><a name="a664"></a></span><span class="src-str">    /**</span></li>
<li><a name="a665"></a></span><span class="src-str">     *  Find all records using a &quot;belongs_to&quot; relationship (one-to-one)</span></li>
<li><a name="a666"></a></span><span class="src-str">     *  (the foreign key being in the table itself)</span></li>
<li><a name="a667"></a></span><span class="src-str">     *  Parameters: $other_object_name: The singularized version of a table name.</span></li>
<li><a name="a668"></a></span><span class="src-str">     *                                  E.g. If the Contact class belongs_to the</span></li>
<li><a name="a669"></a></span><span class="src-str">     *                                  Customer class, then $other_object_name</span></li>
<li><a name="a670"></a></span><span class="src-str">     *                                  will be &quot;customer&quot;.</span></li>
<li><a name="a671"></a></span><span class="src-str">     *  @todo Document this API</span></li>
<li><a name="a672"></a></span><span class="src-str">     */</span></li>
<li><a name="a673"></a></span><span class="src-str">    <span class="src-key">private</span> <span class="src-key">function</span> <span class="src-id">find_one_belongs_to</span><span class="src-sym">(</span><span class="src-var">$other_object_name</span><span class="src-sym">,</span> <span class="src-var">$parameters</span> = <span class="src-id">null</span><span class="src-sym">)</span> <span class="src-sym">{</span></span></li>
<li><a name="a674"></a></span><span class="src-str">        <span class="src-comm"># Prepare the class name and primary key, e.g. if</span></span></li>
<li><a name="a675"></a></span><span class="src-str"><span class="src-comm"></span>        <span class="src-comm"># customers has_many contacts, then we'll need a Contact</span></span></li>
<li><a name="a676"></a></span><span class="src-str"><span class="src-comm"></span>        <span class="src-comm"># object, and the customer_id field name.</span></span></li>
<li><a name="a677"></a></span><span class="src-str"><span class="src-comm"></span>        <span class="src-var">$other_class_name</span> = <span class="src-id">Inflector</span><span class="src-sym">::</span><span class="src-id">camelize</span><span class="src-sym">(</span><span class="src-var">$other_object_name</span><span class="src-sym">)</span><span class="src-sym">;</span></span></li>
<li><a name="a678"></a></span><span class="src-str">        <span class="src-key">if</span><span class="src-sym">(</span><span class="src-sym">@</span><span class="src-id">array_key_exists</span><span class="src-sym">(</span><span class="src-str">&quot;foreign_key&quot;</span><span class="src-sym">,</span> <span class="src-var">$parameters</span><span class="src-sym">))</span></span></li>
<li><a name="a679"></a></span><span class="src-str">            <span class="src-var">$foreign_key</span> = <span class="src-var">$parameters</span><span class="src-sym">[</span><span class="src-str">'foreign_key'</span><span class="src-sym">]</span><span class="src-sym">;</span></span></li>
<li><a name="a680"></a></span><span class="src-str">        <span class="src-key">else</span></span></li>
<li><a name="a681"></a></span><span class="src-str">            <span class="src-var">$foreign_key</span> = <span class="src-var">$other_object_name</span>.<span class="src-str">&quot;_id&quot;</span><span class="src-sym">;</span></span></li>
<li><a name="a682"></a>&nbsp;</li>
<li><a name="a683"></a></span><span class="src-str">        <span class="src-var">$conditions</span> = <span class="src-str">&quot;id='&quot;</span>.<span class="src-var">$this</span></span><span class="src-sym">-&gt;</span><span class="src-var">$foreign_key</span>.<span class="src-str">&quot;'&quot;</span><span class="src-sym">;</span></li>
<li><a name="a684"></a>        <span class="src-comm"># Instantiate an object to access find_all</span></li>
<li><a name="a685"></a>        <span class="src-var">$results </span>= <span class="src-key">new </span><span class="src-var">$other_class_name</span><span class="src-sym">(</span><span class="src-sym">)</span><span class="src-sym">;</span></li>
<li><a name="a686"></a>        <span class="src-comm"># Get the list of other_class_name objects</span></li>
<li><a name="a687"></a>        <span class="src-var">$results </span>= <span class="src-var">$results</span><span class="src-sym">-&gt;</span><span class="src-id">find_first</span><span class="src-sym">(</span><span class="src-var">$conditions</span><span class="src-sym">, </span><span class="src-var">$orderings</span><span class="src-sym">)</span><span class="src-sym">;</span></li>
<li><a name="a688"></a>        <span class="src-comm"># There should only be one result, an object, if so return it</span></li>
<li><a name="a689"></a>        <span class="src-key">if</span><span class="src-sym">(</span><span class="src-id">is_object</span><span class="src-sym">(</span><span class="src-var">$results</span><span class="src-sym">)) </span><span class="src-str"></span><span class="src-sym">{</span></span></li>
<li><a name="a690"></a></span><span class="src-str">            <span class="src-key">return</span> <span class="src-var">$results</span><span class="src-sym">;</span></span></li>
<li><a name="a691"></a></span><span class="src-str">        <span class="src-sym">}</span> <span class="src-key">else</span> <span class="src-sym">{</span></span></li>
<li><a name="a692"></a></span><span class="src-str">            <span class="src-key">return</span> <span class="src-id">null</span><span class="src-sym">;</span></span></li>
<li><a name="a693"></a></span><span class="src-str">        <span class="src-sym">}</span></span></li>
<li><a name="a694"></a></span><span class="src-str">    <span class="src-sym">}</span></span></li>
<li><a name="a695"></a>&nbsp;</li>
<li><a name="a696"></a></span><span class="src-str">    /**</span></li>
<li><a name="a697"></a></span><span class="src-str">     *  Implement *_all() functions (SQL aggregate functions)</span></li>
<li><a name="a698"></a></span><span class="src-str">     *</span></li>
<li><a name="a699"></a></span><span class="src-str">     *  Apply one of the SQL aggregate functions to a column of the</span></li>
<li><a name="a700"></a></span><span class="src-str">     *  table associated with this object.  The SQL aggregate</span></li>
<li><a name="a701"></a></span><span class="src-str">     *  functions are AVG, COUNT, MAX, MIN and SUM.  Not all DBMS's</span></li>
<li><a name="a702"></a></span><span class="src-str">     *  implement all of these functions.</span></li>
<li><a name="a703"></a></span><span class="src-str">     *  @param string $agrregrate_type SQL aggregate function to</span></li>
<li><a name="a704"></a></span><span class="src-str">     *    apply, suffixed '_all'.  The aggregate function is one of</span></li>
<li><a name="a705"></a></span><span class="src-str">     *  the strings in {@link $aggregrations}. </span></li>
<li><a name="a706"></a></span><span class="src-str">     *  @param string[] $parameters  Conditions to apply to the</span></li>
<li><a name="a707"></a></span><span class="src-str">     *    aggregate function.  If present, must be an array of three</span></li>
<li><a name="a708"></a></span><span class="src-str">     *    strings:&lt;ol&gt;</span></li>
<li><a name="a709"></a></span><span class="src-str">     *     &lt;li&gt;$parameters[0]: If present, expression to apply</span></li>
<li><a name="a710"></a></span><span class="src-str">     *       the aggregate function to.  Otherwise, '*' will be used.</span></li>
<li><a name="a711"></a></span><span class="src-str">     *       &lt;b&gt;NOTE:&lt;/b&gt;SQL uses '*' only for the COUNT() function,</span></li>
<li><a name="a712"></a></span><span class="src-str">     *       where it means &quot;including rows with NULL in this column&quot;.&lt;/li&gt;</span></li>
<li><a name="a713"></a></span><span class="src-str">     *     &lt;li&gt;$parameters[1]: argument to WHERE clause&lt;/li&gt;</span></li>
<li><a name="a714"></a></span><span class="src-str">     *     &lt;li&gt;$parameters[2]: joins??? @todo Document this parameter&lt;/li&gt;</span></li>
<li><a name="a715"></a></span><span class="src-str">     *    &lt;/ol&gt;</span></li>
<li><a name="a716"></a></span><span class="src-str">     *  @throws {@link ActiveRecordError}</span></li>
<li><a name="a717"></a></span><span class="src-str">     *  @uses query()</span></li>
<li><a name="a718"></a></span><span class="src-str">     *  @uses is_error()</span></li>
<li><a name="a719"></a></span><span class="src-str">     */</span></li>
<li><a name="a720"></a></span><span class="src-str">    <span class="src-key">private</span> <span class="src-key">function</span> <span class="src-id">aggregrate_all</span><span class="src-sym">(</span><span class="src-var">$aggregrate_type</span><span class="src-sym">,</span> <span class="src-var">$parameters</span> = <span class="src-id">null</span><span class="src-sym">)</span> <span class="src-sym">{</span></span></li>
<li><a name="a721"></a></span><span class="src-str">        <span class="src-var">$aggregrate_type</span> = <span class="src-id">strtoupper</span><span class="src-sym">(</span><span class="src-id">substr</span><span class="src-sym">(</span><span class="src-var">$aggregrate_type</span><span class="src-sym">,</span> <span class="src-num">0</span><span class="src-sym">,</span> -<span class="src-num">4</span><span class="src-sym">))</span><span class="src-sym">;</span></span></li>
<li><a name="a722"></a></span><span class="src-str">        <span class="src-sym">(</span><span class="src-var">$parameters</span><span class="src-sym">[</span><span class="src-num">0</span><span class="src-sym">]</span><span class="src-sym">)</span> ? <span class="src-var">$field</span> = <span class="src-var">$parameters</span><span class="src-sym">[</span><span class="src-num">0</span><span class="src-sym">]</span> : <span class="src-var">$field</span> = <span class="src-str">&quot;*&quot;</span><span class="src-sym">;</span></span></li>
<li><a name="a723"></a></span><span class="src-str">        <span class="src-var">$sql</span> = <span class="src-str">"</span><span class="src-id">SELECT</span> <span class="src-var">$aggregrate_type</span>(<span class="src-var">$field</span>) <span class="src-id">AS</span> <span class="src-id">agg_result</span> <span class="src-id">FROM</span> <span class="src-var">$this</span></span><span class="src-sym">-&gt;</span><a href="../PHPonTrax/ActiveRecord.html#var$table_name">table_name</a> </span><span class="src-str"><span class="src-str">"</span><span class="src-sym">;</span></span></li>
<li><a name="a724"></a></span><span class="src-str">        </span></li>
<li><a name="a725"></a></span><span class="src-str">        <span class="src-comm"># Use any passed-in parameters</span></span></li>
<li><a name="a726"></a></span><span class="src-str"><span class="src-comm"></span>        <span class="src-key">if</span> <span class="src-sym">(</span><span class="src-sym">!</span><span class="src-id">is_null</span><span class="src-sym">(</span><span class="src-var">$parameters</span><span class="src-sym">))</span> <span class="src-sym">{</span></span></li>
<li><a name="a727"></a></span><span class="src-str">            <span class="src-var">$conditions</span> = <span class="src-var">$parameters</span><span class="src-sym">[</span><span class="src-num">1</span><span class="src-sym">]</span><span class="src-sym">;</span></span></li>
<li><a name="a728"></a></span><span class="src-str">            <span class="src-var">$joins</span> = <span class="src-var">$parameters</span><span class="src-sym">[</span><span class="src-num">2</span><span class="src-sym">]</span><span class="src-sym">;</span></span></li>
<li><a name="a729"></a></span><span class="src-str">        <span class="src-sym">}</span></span></li>
<li><a name="a730"></a>&nbsp;</li>
<li><a name="a731"></a></span><span class="src-str">        <span class="src-key">if</span><span class="src-sym">(</span><span class="src-sym">!</span><span class="src-key">empty</span><span class="src-sym">(</span><span class="src-var">$joins</span><span class="src-sym">))</span> <span class="src-var">$sql</span> .= <span class="src-str">"</span>,<span class="src-var">$joins</span> <span class="src-str">"</span><span class="src-sym">;</span></span></li>
<li><a name="a732"></a></span><span class="src-str">        <span class="src-key">if</span><span class="src-sym">(</span><span class="src-sym">!</span><span class="src-key">empty</span><span class="src-sym">(</span><span class="src-var">$conditions</span><span class="src-sym">))</span> <span class="src-var">$sql</span> .= <span class="src-str">"</span><span class="src-id">WHERE</span> <span class="src-var">$conditions</span> <span class="src-str">"</span><span class="src-sym">;</span></span></li>
<li><a name="a733"></a>&nbsp;</li>
<li><a name="a734"></a></span><span class="src-str">        <span class="src-comm">//echo &quot;sql:$sql&lt;br&gt;&quot;;</span></span></li>
<li><a name="a735"></a></span><span class="src-str"><span class="src-comm"></span>        <span class="src-key">if</span><span class="src-sym">(</span><span class="src-var">$this</span></span><span class="src-sym">-&gt;</span><a href="../PHPonTrax/ActiveRecord.html#methodis_error">is_error</a><span class="src-sym">(</span><span class="src-var">$rs </span>= <span class="src-var">$this</span><span class="src-sym">-&gt;</span><a href="../PHPonTrax/ActiveRecord.html#methodquery">query</a><span class="src-sym">(</span><span class="src-var">$sql</span><span class="src-sym">))) </span><span class="src-str"></span><span class="src-sym">{</span></span></li>
<li><a name="a736"></a></span><span class="src-str">            <span class="src-var">$this</span></span><span class="src-sym">-&gt;</span><a href="../PHPonTrax/ActiveRecord.html#methodraise">raise</a><span class="src-sym">(</span><span class="src-var">$rs</span><span class="src-sym">-&gt;</span><span class="src-id">getMessage</span><span class="src-sym">(</span><span class="src-sym">))</span><span class="src-sym">;</span></li>
<li><a name="a737"></a>        </span><span class="src-str"><span class="src-sym">}</span> <span class="src-key">else</span> <span class="src-sym">{</span></span></li>
<li><a name="a738"></a></span><span class="src-str">            <span class="src-var">$row</span> = <span class="src-var">$rs</span></span><span class="src-sym">-&gt;</span><span class="src-id">fetchRow</span><span class="src-sym">(</span><span class="src-sym">)</span><span class="src-sym">;</span></li>
<li><a name="a739"></a>            <span class="src-key">return </span><span class="src-var">$row</span><span class="src-sym">[</span><span class="src-str">&quot;agg_result&quot;</span><span class="src-sym">]</span><span class="src-sym">;</span></li>
<li><a name="a740"></a>        </span><span class="src-str"><span class="src-sym">}</span></span></li>
<li><a name="a741"></a></span><span class="src-str">        <span class="src-key">return</span> <span class="src-num">0</span><span class="src-sym">;</span></span></li>
<li><a name="a742"></a></span><span class="src-str">    <span class="src-sym">}</span></span></li>
<li><a name="a743"></a>&nbsp;</li>
<li><a name="a744"></a></span><span class="src-str">    /**</span></li>
<li><a name="a745"></a></span><span class="src-str">     *  Test whether this object represents a new record</span></li>
<li><a name="a746"></a></span><span class="src-str">     *  @uses $new_record</span></li>
<li><a name="a747"></a></span><span class="src-str">     *  @return boolean Whether this object represents a new record</span></li>
<li><a name="a748"></a></span><span class="src-str">     */</span></li>
<li><a name="a749"></a></span><span class="src-str">   <span class="src-key">function</span> <span class="src-id">is_new_record</span><span class="src-sym">(</span><span class="src-sym">)</span> <span class="src-sym">{</span></span></li>
<li><a name="a750"></a></span><span class="src-str">        <span class="src-key">return</span> <span class="src-var">$this</span></span><span class="src-sym">-&gt;</span><a href="../PHPonTrax/ActiveRecord.html#var$new_record">new_record</a><span class="src-sym">;</span></li>
<li><a name="a751"></a>    </span><span class="src-str"><span class="src-sym">}</span></span></li>
<li><a name="a752"></a>&nbsp;</li>
<li><a name="a753"></a></span><span class="src-str">   /**</span></li>
<li><a name="a754"></a></span><span class="src-str">    *  get the attributes for a specific column.</span></li>
<li><a name="a755"></a></span><span class="src-str">    *  @uses $content_columns</span></li>
<li><a name="a756"></a></span><span class="src-str">    *  @todo Document this API</span></li>
<li><a name="a757"></a></span><span class="src-str">    */</span></li>
<li><a name="a758"></a></span><span class="src-str">    <span class="src-key">function</span> <span class="src-id">column_for_attribute</span><span class="src-sym">(</span><span class="src-var">$attribute</span><span class="src-sym">)</span> <span class="src-sym">{</span></span></li>
<li><a name="a759"></a></span><span class="src-str">        <span class="src-key">if</span><span class="src-sym">(</span><span class="src-id">is_array</span><span class="src-sym">(</span><span class="src-var">$this</span></span><span class="src-sym">-&gt;</span><a href="../PHPonTrax/ActiveRecord.html#var$content_columns">content_columns</a><span class="src-sym">)) </span><span class="src-str"></span><span class="src-sym">{</span></span></li>
<li><a name="a760"></a></span><span class="src-str">            <span class="src-key">foreach</span><span class="src-sym">(</span><span class="src-var">$this</span></span><span class="src-sym">-&gt;</span><a href="../PHPonTrax/ActiveRecord.html#var$content_columns">content_columns</a> <span class="src-key">as </span><span class="src-var">$column</span><span class="src-sym">) </span><span class="src-str"></span><span class="src-sym">{</span></span></li>
<li><a name="a761"></a></span><span class="src-str">                <span class="src-key">if</span><span class="src-sym">(</span><span class="src-var">$column</span><span class="src-sym">[</span><span class="src-str">'name'</span><span class="src-sym">]</span> == <span class="src-var">$attribute</span><span class="src-sym">)</span> <span class="src-sym">{</span></span></li>
<li><a name="a762"></a></span><span class="src-str">                    <span class="src-key">return</span> <span class="src-var">$column</span><span class="src-sym">;</span></span></li>
<li><a name="a763"></a></span><span class="src-str">                <span class="src-sym">}</span></span></li>
<li><a name="a764"></a></span><span class="src-str">            <span class="src-sym">}</span></span></li>
<li><a name="a765"></a></span><span class="src-str">        <span class="src-sym">}</span></span></li>
<li><a name="a766"></a></span><span class="src-str">        <span class="src-key">return</span> <span class="src-id">null</span><span class="src-sym">;</span></span></li>
<li><a name="a767"></a></span><span class="src-str">    <span class="src-sym">}</span></span></li>
<li><a name="a768"></a></span><span class="src-str">    </span></li>
<li><a name="a769"></a></span><span class="src-str">    /**</span></li>
<li><a name="a770"></a></span><span class="src-str">     *  Check whether a column exists in the associated table</span></li>
<li><a name="a771"></a></span><span class="src-str">     *</span></li>
<li><a name="a772"></a></span><span class="src-str">     *  When called, {@link $content_columns} lists the columns in</span></li>
<li><a name="a773"></a></span><span class="src-str">     *  the table described by this object.</span></li>
<li><a name="a774"></a></span><span class="src-str">     *  @param string Name of the column</span></li>
<li><a name="a775"></a></span><span class="src-str">     *  @return boolean true=&gt;the column exists; false=&gt;it doesn't</span></li>
<li><a name="a776"></a></span><span class="src-str">     *  @uses content_columns</span></li>
<li><a name="a777"></a></span><span class="src-str">     */</span></li>
<li><a name="a778"></a></span><span class="src-str">    <span class="src-key">function</span> <span class="src-id">column_attribute_exists</span><span class="src-sym">(</span><span class="src-var">$attribute</span><span class="src-sym">)</span> <span class="src-sym">{</span></span></li>
<li><a name="a779"></a></span><span class="src-str">        <span class="src-key">if</span><span class="src-sym">(</span><span class="src-id">is_array</span><span class="src-sym">(</span><span class="src-var">$this</span></span><span class="src-sym">-&gt;</span><a href="../PHPonTrax/ActiveRecord.html#var$content_columns">content_columns</a><span class="src-sym">)) </span><span class="src-str"></span><span class="src-sym">{</span></span></li>
<li><a name="a780"></a></span><span class="src-str">            <span class="src-key">foreach</span><span class="src-sym">(</span><span class="src-var">$this</span></span><span class="src-sym">-&gt;</span><a href="../PHPonTrax/ActiveRecord.html#var$content_columns">content_columns</a> <span class="src-key">as </span><span class="src-var">$column</span><span class="src-sym">) </span><span class="src-str"></span><span class="src-sym">{</span></span></li>
<li><a name="a781"></a></span><span class="src-str">                <span class="src-key">if</span><span class="src-sym">(</span><span class="src-var">$column</span><span class="src-sym">[</span><span class="src-str">'name'</span><span class="src-sym">]</span> == <span class="src-var">$attribute</span><span class="src-sym">)</span> <span class="src-sym">{</span></span></li>
<li><a name="a782"></a></span><span class="src-str">                    <span class="src-key">return</span> <span class="src-id">true</span><span class="src-sym">;</span></span></li>
<li><a name="a783"></a></span><span class="src-str">                <span class="src-sym">}</span></span></li>
<li><a name="a784"></a></span><span class="src-str">            <span class="src-sym">}</span></span></li>
<li><a name="a785"></a></span><span class="src-str">        <span class="src-sym">}</span> </span></li>
<li><a name="a786"></a></span><span class="src-str">        <span class="src-key">return</span> <span class="src-id">false</span><span class="src-sym">;</span>     </span></li>
<li><a name="a787"></a></span><span class="src-str">    <span class="src-sym">}</span></span></li>
<li><a name="a788"></a>&nbsp;</li>
<li><a name="a789"></a></span><span class="src-str">    /**</span></li>
<li><a name="a790"></a></span><span class="src-str">     *  Get contents of one column of record selected by id and table</span></li>
<li><a name="a791"></a></span><span class="src-str">     *</span></li>
<li><a name="a792"></a></span><span class="src-str">     *  When called, {@link $id} identifies one record in the table</span></li>
<li><a name="a793"></a></span><span class="src-str">     *  identified by {@link $table}.  Fetch from the database the</span></li>
<li><a name="a794"></a></span><span class="src-str">     *  contents of column $column of this record.</span></li>
<li><a name="a795"></a></span><span class="src-str">     *  @param string Name of column to retrieve</span></li>
<li><a name="a796"></a></span><span class="src-str">     *  @uses $db</span></li>
<li><a name="a797"></a></span><span class="src-str">     *  @uses column_attribute_exists()</span></li>
<li><a name="a798"></a></span><span class="src-str">     *  @throws {@link ActiveRecordError}</span></li>
<li><a name="a799"></a></span><span class="src-str">     *  @uses is_error()</span></li>
<li><a name="a800"></a></span><span class="src-str">     */</span></li>
<li><a name="a801"></a></span><span class="src-str">    <span class="src-key">function</span> <span class="src-id">send</span><span class="src-sym">(</span><span class="src-var">$column</span><span class="src-sym">)</span> <span class="src-sym">{</span></span></li>
<li><a name="a802"></a></span><span class="src-str">        <span class="src-key">if</span><span class="src-sym">(</span><span class="src-var">$this</span></span><span class="src-sym">-&gt;</span><a href="../PHPonTrax/ActiveRecord.html#methodcolumn_attribute_exists">column_attribute_exists</a><span class="src-sym">(</span><span class="src-var">$column</span><span class="src-sym">)) </span><span class="src-str"></span><span class="src-sym">{</span></span></li>
<li><a name="a803"></a></span><span class="src-str">            <span class="src-comm"># Run the query to grab a specific columns value.</span></span></li>
<li><a name="a804"></a></span><span class="src-str"><span class="src-comm"></span>            <span class="src-var">$sql</span> = <span class="src-str">"</span><span class="src-id">SELECT</span> <span class="src-var">$column</span> <span class="src-id">FROM</span> <span class="src-var">$this</span></span><span class="src-sym">-&gt;</span><a href="../PHPonTrax/ActiveRecord.html#var$table_name">table_name</a> <span class="src-id">WHERE id</span>='<span class="src-var">$this</span><span class="src-sym">-&gt;</span><span class="src-var">id</span>'</span><span class="src-str"><span class="src-str">"</span><span class="src-sym">;</span></span></li>
<li><a name="a805"></a></span><span class="src-str">            <span class="src-var">$this</span></span><span class="src-sym">-&gt;</span><a href="../PHPonTrax/ActiveRecord.html#methodlog_query">log_query</a><span class="src-sym">(</span><span class="src-var">$sql</span><span class="src-sym">)</span><span class="src-sym">;</span></li>
<li><a name="a806"></a>            <span class="src-var">$result </span>= <span class="src-id">self</span><span class="src-sym">::</span><span class="src-var">$db</span><span class="src-sym">-&gt;</span><span class="src-id">getOne</span><span class="src-sym">(</span><span class="src-var">$sql</span><span class="src-sym">)</span><span class="src-sym">;</span></li>
<li><a name="a807"></a>            <span class="src-key">if</span><span class="src-sym">(</span><span class="src-var">$this</span><span class="src-sym">-&gt;</span><a href="../PHPonTrax/ActiveRecord.html#methodis_error">is_error</a><span class="src-sym">(</span><span class="src-var">$result</span><span class="src-sym">)) </span><span class="src-str"></span><span class="src-sym">{</span></span></li>
<li><a name="a808"></a></span><span class="src-str">                <span class="src-var">$this</span></span><span class="src-sym">-&gt;</span><a href="../PHPonTrax/ActiveRecord.html#methodraise">raise</a><span class="src-sym">(</span><span class="src-var">$result</span><span class="src-sym">-&gt;</span><span class="src-id">getMessage</span><span class="src-sym">(</span><span class="src-sym">))</span><span class="src-sym">;</span></li>
<li><a name="a809"></a>            </span><span class="src-str"><span class="src-sym">}</span></span></li>
<li><a name="a810"></a></span><span class="src-str">        <span class="src-sym">}</span></span></li>
<li><a name="a811"></a></span><span class="src-str">        <span class="src-key">return</span> <span class="src-var">$result</span><span class="src-sym">;</span></span></li>
<li><a name="a812"></a></span><span class="src-str">    <span class="src-sym">}</span></span></li>
<li><a name="a813"></a>&nbsp;</li>
<li><a name="a814"></a></span><span class="src-str">    /**</span></li>
<li><a name="a815"></a></span><span class="src-str">     * Only used if you want to do transactions and your db supports transactions</span></li>
<li><a name="a816"></a></span><span class="src-str">     *</span></li>
<li><a name="a817"></a></span><span class="src-str">     *  @uses $db</span></li>
<li><a name="a818"></a></span><span class="src-str">     *  @todo Document this API</span></li>
<li><a name="a819"></a></span><span class="src-str">     */</span></li>
<li><a name="a820"></a></span><span class="src-str">    <span class="src-key">function</span> <span class="src-id">begin</span><span class="src-sym">(</span><span class="src-sym">)</span> <span class="src-sym">{</span></span></li>
<li><a name="a821"></a></span><span class="src-str">        <span class="src-id">self</span><span class="src-sym">::</span><span class="src-var">$db</span></span><span class="src-sym">-&gt;</span><span class="src-id">query</span><span class="src-sym">(</span><span class="src-str">&quot;BEGIN&quot;</span><span class="src-sym">)</span><span class="src-sym">;</span></li>
<li><a name="a822"></a>        <span class="src-var">$this</span><span class="src-sym">-&gt;</span><a href="../PHPonTrax/ActiveRecord.html#var$begin_executed">begin_executed</a> = <span class="src-id">true</span><span class="src-sym">;</span></li>
<li><a name="a823"></a>    </span><span class="src-str"><span class="src-sym">}</span></span></li>
<li><a name="a824"></a>&nbsp;</li>
<li><a name="a825"></a></span><span class="src-str">    /**</span></li>
<li><a name="a826"></a></span><span class="src-str">     *  Only used if you want to do transactions and your db supports transactions</span></li>
<li><a name="a827"></a></span><span class="src-str">     *</span></li>
<li><a name="a828"></a></span><span class="src-str">     *  @uses $db</span></li>
<li><a name="a829"></a></span><span class="src-str">     *  @todo Document this API</span></li>
<li><a name="a830"></a></span><span class="src-str">     */</span></li>
<li><a name="a831"></a></span><span class="src-str">    <span class="src-key">function</span> <span class="src-id">commit</span><span class="src-sym">(</span><span class="src-sym">)</span> <span class="src-sym">{</span></span></li>
<li><a name="a832"></a></span><span class="src-str">        <span class="src-id">self</span><span class="src-sym">::</span><span class="src-var">$db</span></span><span class="src-sym">-&gt;</span><span class="src-id">query</span><span class="src-sym">(</span><span class="src-str">&quot;COMMIT&quot;</span><span class="src-sym">)</span><span class="src-sym">; </span></li>
<li><a name="a833"></a>        <span class="src-var">$this</span><span class="src-sym">-&gt;</span><a href="../PHPonTrax/ActiveRecord.html#var$begin_executed">begin_executed</a> = <span class="src-id">false</span><span class="src-sym">;</span></li>
<li><a name="a834"></a>    </span><span class="src-str"><span class="src-sym">}</span></span></li>
<li><a name="a835"></a>&nbsp;</li>
<li><a name="a836"></a></span><span class="src-str">    /**</span></li>
<li><a name="a837"></a></span><span class="src-str">     *  Only used if you want to do transactions and your db supports transactions</span></li>
<li><a name="a838"></a></span><span class="src-str">     *</span></li>
<li><a name="a839"></a></span><span class="src-str">     *  @uses $db</span></li>
<li><a name="a840"></a></span><span class="src-str">     *  @todo Document this API</span></li>
<li><a name="a841"></a></span><span class="src-str">     */</span></li>
<li><a name="a842"></a></span><span class="src-str">    <span class="src-key">function</span> <span class="src-id">rollback</span><span class="src-sym">(</span><span class="src-sym">)</span> <span class="src-sym">{</span></span></li>
<li><a name="a843"></a></span><span class="src-str">        <span class="src-id">self</span><span class="src-sym">::</span><span class="src-var">$db</span></span><span class="src-sym">-&gt;</span><span class="src-id">query</span><span class="src-sym">(</span><span class="src-str">&quot;ROLLBACK&quot;</span><span class="src-sym">)</span><span class="src-sym">;</span></li>
<li><a name="a844"></a>    </span><span class="src-str"><span class="src-sym">}</span></span></li>
<li><a name="a845"></a>&nbsp;</li>
<li><a name="a846"></a></span><span class="src-str">    /**</span></li>
<li><a name="a847"></a></span><span class="src-str">     *  Perform an SQL query and return the results</span></li>
<li><a name="a848"></a></span><span class="src-str">     *</span></li>
<li><a name="a849"></a></span><span class="src-str">     *  @param string $sql  SQL for the query command</span></li>
<li><a name="a850"></a></span><span class="src-str">     *  @return DB_result {@link http://pear.php.net/manual/en/package.database.db.db-result.php}</span></li>
<li><a name="a851"></a></span><span class="src-str">     *    Result set from query</span></li>
<li><a name="a852"></a></span><span class="src-str">     *  @uses $db</span></li>
<li><a name="a853"></a></span><span class="src-str">     *  @uses is_error()</span></li>
<li><a name="a854"></a></span><span class="src-str">     *  @uses log_query()</span></li>
<li><a name="a855"></a></span><span class="src-str">     *  @throws {@link ActiveRecordError}</span></li>
<li><a name="a856"></a></span><span class="src-str">     */</span></li>
<li><a name="a857"></a></span><span class="src-str">    <span class="src-key">function</span> <span class="src-id">query</span><span class="src-sym">(</span><span class="src-var">$sql</span><span class="src-sym">)</span> <span class="src-sym">{</span></span></li>
<li><a name="a858"></a></span><span class="src-str">        <span class="src-comm"># Run the query</span></span></li>
<li><a name="a859"></a></span><span class="src-str"><span class="src-comm"></span>        <span class="src-var">$this</span></span><span class="src-sym">-&gt;</span><a href="../PHPonTrax/ActiveRecord.html#methodlog_query">log_query</a><span class="src-sym">(</span><span class="src-var">$sql</span><span class="src-sym">)</span><span class="src-sym">;</span></li>
<li><a name="a860"></a>        <span class="src-var">$rs </span>= <span class="src-id">self</span><span class="src-sym">::</span><span class="src-var">$db</span><span class="src-sym">-&gt;</span><span class="src-id">query</span><span class="src-sym">(</span><span class="src-var">$sql</span><span class="src-sym">)</span><span class="src-sym">;</span></li>
<li><a name="a861"></a>        <span class="src-key">if </span><span class="src-sym">(</span><span class="src-var">$this</span><span class="src-sym">-&gt;</span><a href="../PHPonTrax/ActiveRecord.html#methodis_error">is_error</a><span class="src-sym">(</span><span class="src-var">$rs</span><span class="src-sym">)) </span><span class="src-str"></span><span class="src-sym">{</span></span></li>
<li><a name="a862"></a></span><span class="src-str">            <span class="src-key">if</span><span class="src-sym">(</span><span class="src-id">self</span><span class="src-sym">::</span><span class="src-var">$use_transactions</span> &amp;&amp; <span class="src-id">self</span><span class="src-sym">::</span><span class="src-var">$begin_executed</span><span class="src-sym">)</span> <span class="src-sym">{</span></span></li>
<li><a name="a863"></a></span><span class="src-str">                <span class="src-var">$this</span></span><span class="src-sym">-&gt;</span><a href="../PHPonTrax/ActiveRecord.html#methodrollback">rollback</a><span class="src-sym">(</span><span class="src-sym">)</span><span class="src-sym">;</span></li>
<li><a name="a864"></a>            </span><span class="src-str"><span class="src-sym">}</span></span></li>
<li><a name="a865"></a></span><span class="src-str">            <span class="src-var">$this</span></span><span class="src-sym">-&gt;</span><a href="../PHPonTrax/ActiveRecord.html#methodraise">raise</a><span class="src-sym">(</span><span class="src-var">$rs</span><span class="src-sym">-&gt;</span><span class="src-id">getMessage</span><span class="src-sym">(</span><span class="src-sym">))</span><span class="src-sym">;</span></li>
<li><a name="a866"></a>        </span><span class="src-str"><span class="src-sym">}</span></span></li>
<li><a name="a867"></a></span><span class="src-str">        <span class="src-key">return</span> <span class="src-var">$rs</span><span class="src-sym">;</span></span></li>
<li><a name="a868"></a></span><span class="src-str">    <span class="src-sym">}</span></span></li>
<li><a name="a869"></a>&nbsp;</li>
<li><a name="a870"></a></span><span class="src-str">    /**</span></li>
<li><a name="a871"></a></span><span class="src-str">     *  Implement find_by_*() and find_all_by_* methods</span></li>
<li><a name="a872"></a></span><span class="src-str">     *  </span></li>
<li><a name="a873"></a></span><span class="src-str">     *  Converts a method name beginning 'find_by_' or 'find_all_by_'</span></li>
<li><a name="a874"></a></span><span class="src-str">     *  into a query for rows matching the rest of the method name and</span></li>
<li><a name="a875"></a></span><span class="src-str">     *  the arguments to the function.  The part of the method name</span></li>
<li><a name="a876"></a></span><span class="src-str">     *  after '_by' is parsed for columns and logical relationships</span></li>
<li><a name="a877"></a></span><span class="src-str">     *  (AND and OR) to match.  For example, the call</span></li>
<li><a name="a878"></a></span><span class="src-str">     *    find_by_fname('Ben')</span></li>
<li><a name="a879"></a></span><span class="src-str">     *  is converted to</span></li>
<li><a name="a880"></a></span><span class="src-str">     *    SELECT * ... WHERE fname='Ben'</span></li>
<li><a name="a881"></a></span><span class="src-str">     *  and the call</span></li>
<li><a name="a882"></a></span><span class="src-str">     *    find_by_fname_and_lname('Ben','Dover')</span></li>
<li><a name="a883"></a></span><span class="src-str">     *  is converted to</span></li>
<li><a name="a884"></a></span><span class="src-str">     *    SELECT * ... WHERE fname='Ben' AND lname='Dover'</span></li>
<li><a name="a885"></a></span><span class="src-str">     *  </span></li>
<li><a name="a886"></a></span><span class="src-str">     *  @uses find_all()</span></li>
<li><a name="a887"></a></span><span class="src-str">     *  @uses find_first()</span></li>
<li><a name="a888"></a></span><span class="src-str">     */</span></li>
<li><a name="a889"></a></span><span class="src-str">    <span class="src-key">private</span> <span class="src-key">function</span> <span class="src-id">find_by</span><span class="src-sym">(</span><span class="src-var">$method_name</span><span class="src-sym">,</span> <span class="src-var">$parameters</span><span class="src-sym">,</span> <span class="src-var">$find_all</span> = <span class="src-id">false</span><span class="src-sym">)</span> <span class="src-sym">{</span></span></li>
<li><a name="a890"></a></span><span class="src-str">    <span class="src-var">$method_parts</span> = <span class="src-id">explode</span><span class="src-sym">(</span><span class="src-str">&quot;_&quot;</span><span class="src-sym">,</span><span class="src-id">substr</span><span class="src-sym">(</span><span class="src-var">$method_name</span><span class="src-sym">,</span> <span class="src-sym">(</span><span class="src-var">$find_all</span> ? <span class="src-num">12</span> : <span class="src-num">8</span><span class="src-sym">)))</span><span class="src-sym">;</span></span></li>
<li><a name="a891"></a></span><span class="src-str">        <span class="src-key">if</span><span class="src-sym">(</span><span class="src-id">is_array</span><span class="src-sym">(</span><span class="src-var">$method_parts</span><span class="src-sym">))</span> <span class="src-sym">{</span></span></li>
<li><a name="a892"></a></span><span class="src-str">            <span class="src-var">$param_cnt</span> = <span class="src-num">0</span><span class="src-sym">;</span></span></li>
<li><a name="a893"></a></span><span class="src-str">            <span class="src-var">$part_cnt</span> = <span class="src-num">1</span><span class="src-sym">;</span></span></li>
<li><a name="a894"></a></span><span class="src-str">            <span class="src-var">$and_cnt</span> = <span class="src-id">substr_count</span><span class="src-sym">(</span><span class="src-id">strtolower</span><span class="src-sym">(</span><span class="src-var">$method_name</span><span class="src-sym">)</span><span class="src-sym">,</span> <span class="src-str">&quot;_and_&quot;</span><span class="src-sym">)</span><span class="src-sym">;</span></span></li>
<li><a name="a895"></a></span><span class="src-str">            <span class="src-var">$or_cnt</span> = <span class="src-id">substr_count</span><span class="src-sym">(</span><span class="src-id">strtolower</span><span class="src-sym">(</span><span class="src-var">$method_name</span><span class="src-sym">)</span><span class="src-sym">,</span> <span class="src-str">&quot;_or_&quot;</span><span class="src-sym">)</span><span class="src-sym">;</span></span></li>
<li><a name="a896"></a></span><span class="src-str">            <span class="src-var">$part_size</span> = <span class="src-id">count</span><span class="src-sym">(</span><span class="src-var">$method_parts</span><span class="src-sym">)</span> - <span class="src-var">$and_cnt</span> - <span class="src-var">$or_cnt</span><span class="src-sym">;</span></span></li>
<li><a name="a897"></a></span><span class="src-str">            <span class="src-comm">// FIXME: This loop doesn't work right for either</span></span></li>
<li><a name="a898"></a></span><span class="src-str"><span class="src-comm"></span>        <span class="src-comm">// find_by_first_name_and_last_name or</span></span></li>
<li><a name="a899"></a></span><span class="src-str"><span class="src-comm"></span>        <span class="src-comm">// find_all_by_first_name_and_last_name</span></span></li>
<li><a name="a900"></a></span><span class="src-str"><span class="src-comm"></span>            <span class="src-key">foreach</span><span class="src-sym">(</span><span class="src-var">$method_parts</span> <span class="src-key">as</span> <span class="src-var">$part</span><span class="src-sym">)</span> <span class="src-sym">{</span></span></li>
<li><a name="a901"></a></span><span class="src-str">                <span class="src-key">if</span><span class="src-sym">(</span><span class="src-id">strtoupper</span><span class="src-sym">(</span><span class="src-var">$part</span><span class="src-sym">)</span> == <span class="src-str">&quot;AND&quot;</span><span class="src-sym">)</span> <span class="src-sym">{</span></span></li>
<li><a name="a902"></a></span><span class="src-str">                    <span class="src-var">$method_params</span> .= <span class="src-id">implode</span><span class="src-sym">(</span><span class="src-str">&quot;_&quot;</span><span class="src-sym">,</span><span class="src-var">$field</span><span class="src-sym">)</span>.<span class="src-str">&quot;='&quot;</span>.<span class="src-var">$parameters</span><span class="src-sym">[</span><span class="src-var">$param_cnt</span>++<span class="src-sym">]</span>.<span class="src-str">&quot;' AND &quot;</span><span class="src-sym">;</span></span></li>
<li><a name="a903"></a></span><span class="src-str">                    <span class="src-var">$part_cnt</span>--<span class="src-sym">;</span></span></li>
<li><a name="a904"></a></span><span class="src-str">                    unset<span class="src-sym">(</span><span class="src-var">$field</span><span class="src-sym">)</span><span class="src-sym">;</span></span></li>
<li><a name="a905"></a></span><span class="src-str">                <span class="src-sym">}</span> <span class="src-key">elseif</span><span class="src-sym">(</span><span class="src-id">strtoupper</span><span class="src-sym">(</span><span class="src-var">$part</span><span class="src-sym">)</span> == <span class="src-str">&quot;OR&quot;</span><span class="src-sym">)</span> <span class="src-sym">{</span></span></li>
<li><a name="a906"></a></span><span class="src-str">                    <span class="src-var">$method_params</span> .= <span class="src-id">implode</span><span class="src-sym">(</span><span class="src-str">&quot;_&quot;</span><span class="src-sym">,</span><span class="src-var">$field</span><span class="src-sym">)</span>.<span class="src-str">&quot;='&quot;</span>.<span class="src-var">$parameters</span><span class="src-sym">[</span><span class="src-var">$param_cnt</span>++<span class="src-sym">]</span>.<span class="src-str">&quot;' OR &quot;</span><span class="src-sym">;</span></span></li>
<li><a name="a907"></a></span><span class="src-str">                    <span class="src-var">$part_cnt</span>--<span class="src-sym">;</span></span></li>
<li><a name="a908"></a></span><span class="src-str">                    unset<span class="src-sym">(</span><span class="src-var">$field</span><span class="src-sym">)</span><span class="src-sym">;</span></span></li>
<li><a name="a909"></a></span><span class="src-str">                <span class="src-sym">}</span> <span class="src-key">else</span> <span class="src-sym">{</span></span></li>
<li><a name="a910"></a></span><span class="src-str">                    <span class="src-var">$field</span><span class="src-sym">[</span><span class="src-sym">]</span> = <span class="src-var">$part</span><span class="src-sym">;</span></span></li>
<li><a name="a911"></a></span><span class="src-str">                    <span class="src-key">if</span><span class="src-sym">(</span><span class="src-var">$part_size</span> == <span class="src-var">$part_cnt</span><span class="src-sym">)</span> <span class="src-sym">{</span></span></li>
<li><a name="a912"></a></span><span class="src-str">                        <span class="src-var">$method_params</span> .= <span class="src-id">implode</span><span class="src-sym">(</span><span class="src-str">&quot;_&quot;</span><span class="src-sym">,</span><span class="src-var">$field</span><span class="src-sym">)</span>.<span class="src-str">&quot;='&quot;</span>.<span class="src-var">$parameters</span><span class="src-sym">[</span><span class="src-var">$param_cnt</span>++<span class="src-sym">]</span>.<span class="src-str">&quot;'&quot;</span><span class="src-sym">;</span></span></li>
<li><a name="a913"></a></span><span class="src-str">                        <span class="src-key">if</span><span class="src-sym">(</span><span class="src-var">$parameters</span><span class="src-sym">[</span><span class="src-var">$param_cnt</span><span class="src-sym">]</span><span class="src-sym">)</span> <span class="src-sym">{</span></span></li>
<li><a name="a914"></a></span><span class="src-str">                            <span class="src-var">$orderings</span> = <span class="src-var">$parameters</span><span class="src-sym">[</span><span class="src-var">$param_cnt</span><span class="src-sym">]</span><span class="src-sym">;</span></span></li>
<li><a name="a915"></a></span><span class="src-str">                        <span class="src-sym">}</span></span></li>
<li><a name="a916"></a></span><span class="src-str">                    <span class="src-sym">}</span></span></li>
<li><a name="a917"></a></span><span class="src-str">                <span class="src-sym">}</span></span></li>
<li><a name="a918"></a></span><span class="src-str">                <span class="src-var">$part_cnt</span>++<span class="src-sym">;</span></span></li>
<li><a name="a919"></a></span><span class="src-str">            <span class="src-sym">}</span></span></li>
<li><a name="a920"></a>&nbsp;</li>
<li><a name="a921"></a></span><span class="src-str">            <span class="src-key">if</span><span class="src-sym">(</span><span class="src-var">$find_all</span><span class="src-sym">)</span> <span class="src-sym">{</span></span></li>
<li><a name="a922"></a></span><span class="src-str">                <span class="src-key">return</span> <span class="src-var">$this</span></span><span class="src-sym">-&gt;</span><a href="../PHPonTrax/ActiveRecord.html#methodfind_all">find_all</a><span class="src-sym">(</span><span class="src-var">$method_params</span><span class="src-sym">, </span><span class="src-var">$orderings</span><span class="src-sym">)</span><span class="src-sym">;</span></li>
<li><a name="a923"></a>            </span><span class="src-str"><span class="src-sym">}</span> <span class="src-key">else</span> <span class="src-sym">{</span></span></li>
<li><a name="a924"></a></span><span class="src-str">                <span class="src-key">return</span> <span class="src-var">$this</span></span><span class="src-sym">-&gt;</span><a href="../PHPonTrax/ActiveRecord.html#methodfind_first">find_first</a><span class="src-sym">(</span><span class="src-var">$method_params</span><span class="src-sym">, </span><span class="src-var">$orderings</span><span class="src-sym">)</span><span class="src-sym">;</span></li>
<li><a name="a925"></a>            </span><span class="src-str"><span class="src-sym">}</span></span></li>
<li><a name="a926"></a></span><span class="src-str">        <span class="src-sym">}</span></span></li>
<li><a name="a927"></a></span><span class="src-str">    <span class="src-sym">}</span></span></li>
<li><a name="a928"></a>&nbsp;</li>
<li><a name="a929"></a></span><span class="src-str">    /**</span></li>
<li><a name="a930"></a></span><span class="src-str">     *  Return rows selected by $conditions</span></li>
<li><a name="a931"></a></span><span class="src-str">     *</span></li>
<li><a name="a932"></a></span><span class="src-str">     *  If no rows match, an empty array is returned.</span></li>
<li><a name="a933"></a></span><span class="src-str">     *  @param string  SQL to use in the query.  If</span></li>
<li><a name="a934"></a></span><span class="src-str">     *    $conditions contains &quot;SELECT&quot;, then $orderings, $limit and</span></li>
<li><a name="a935"></a></span><span class="src-str">     *    $joins are ignored and the query is completely specified by</span></li>
<li><a name="a936"></a></span><span class="src-str">     *    $conditions.  If $conditions is omitted or does not contain</span></li>
<li><a name="a937"></a></span><span class="src-str">     *    &quot;SELECT&quot;, &quot;SELECT * FROM&quot; will be used.  If $conditions is</span></li>
<li><a name="a938"></a></span><span class="src-str">     *    specified and does not contain &quot;SELECT&quot;, the query will</span></li>
<li><a name="a939"></a></span><span class="src-str">     *    include &quot;WHERE $conditions&quot;.  If $conditions is null, the</span></li>
<li><a name="a940"></a></span><span class="src-str">     *    entire table is returned.</span></li>
<li><a name="a941"></a></span><span class="src-str">     *  @param string  Argument to &quot;ORDER BY&quot; in query.</span></li>
<li><a name="a942"></a></span><span class="src-str">     *    If specified, the query will include</span></li>
<li><a name="a943"></a></span><span class="src-str">     *    &quot;ORDER BY $orderings&quot;. If omitted, no ordering will be</span></li>
<li><a name="a944"></a></span><span class="src-str">     *    applied.  </span></li>
<li><a name="a945"></a></span><span class="src-str">     *  @param integer[] Page, rows per page???</span></li>
<li><a name="a946"></a></span><span class="src-str">     *  @param string ???</span></li>
<li><a name="a947"></a></span><span class="src-str">     *  @todo Document the $limit and $joins parameters</span></li>
<li><a name="a948"></a></span><span class="src-str">     *  @uses $rows_per_page_default</span></li>
<li><a name="a949"></a></span><span class="src-str">     *  @uses $rows_per_page</span></li>
<li><a name="a950"></a></span><span class="src-str">     *  @uses $offset</span></li>
<li><a name="a951"></a></span><span class="src-str">     *  @uses $page</span></li>
<li><a name="a952"></a></span><span class="src-str">     *  @uses is_error()</span></li>
<li><a name="a953"></a></span><span class="src-str">     *  @uses $new_record</span></li>
<li><a name="a954"></a></span><span class="src-str">     *  @uses query()</span></li>
<li><a name="a955"></a></span><span class="src-str">     *  @return object[] Array of objects of the same class as this</span></li>
<li><a name="a956"></a></span><span class="src-str">     *    object, one object for each row returned by the query.</span></li>
<li><a name="a957"></a></span><span class="src-str">     *    If the column 'id' was in the results, it is used as the key</span></li>
<li><a name="a958"></a></span><span class="src-str">     *    for that object in the array.</span></li>
<li><a name="a959"></a></span><span class="src-str">     *  @throws {@link ActiveRecordError}</span></li>
<li><a name="a960"></a></span><span class="src-str">     */</span></li>
<li><a name="a961"></a></span><span class="src-str">    <span class="src-key">function</span> <span class="src-id">find_all</span><span class="src-sym">(</span><span class="src-var">$conditions</span> = <span class="src-id">null</span><span class="src-sym">,</span> <span class="src-var">$orderings</span> = <span class="src-id">null</span><span class="src-sym">,</span></span></li>
<li><a name="a962"></a></span><span class="src-str">                      <span class="src-var">$limit</span> = <span class="src-id">null</span><span class="src-sym">,</span> <span class="src-var">$joins</span> = <span class="src-id">null</span><span class="src-sym">)</span> <span class="src-sym">{</span></span></li>
<li><a name="a963"></a></span><span class="src-str">        <span class="src-comm">//error_log(&quot;find_all(&quot;.(is_null($conditions)?'null':$conditions)</span></span></li>
<li><a name="a964"></a></span><span class="src-str"><span class="src-comm"></span>        <span class="src-comm">//          .', ' . (is_null($orderings)?'null':$orderings)</span></span></li>
<li><a name="a965"></a></span><span class="src-str"><span class="src-comm"></span>        <span class="src-comm">//          .', ' . (is_null($limit)?'null':var_export($limit,true))</span></span></li>
<li><a name="a966"></a></span><span class="src-str"><span class="src-comm"></span>        <span class="src-comm">//          .', ' . (is_null($joins)?'null':$joins).')');</span></span></li>
<li><a name="a967"></a></span><span class="src-str"><span class="src-comm"></span></span></li>
<li><a name="a968"></a></span><span class="src-str">        <span class="src-comm">//  Is output to be generated in pages?</span></span></li>
<li><a name="a969"></a></span><span class="src-str"><span class="src-comm"></span>        <span class="src-key">if</span> <span class="src-sym">(</span><span class="src-id">is_array</span><span class="src-sym">(</span><span class="src-var">$limit</span><span class="src-sym">))</span> <span class="src-sym">{</span></span></li>
<li><a name="a970"></a>&nbsp;</li>
<li><a name="a971"></a></span><span class="src-str">            <span class="src-comm">//  Yes, get next page number and rows per page from argument</span></span></li>
<li><a name="a972"></a></span><span class="src-str"><span class="src-comm"></span>            list<span class="src-sym">(</span><span class="src-var">$this</span></span><span class="src-sym">-&gt;</span><span class="src-var">page</span><span class="src-sym">, </span><span class="src-var">$this</span><span class="src-sym">-&gt;</span><span class="src-var">rows_per_page</span><span class="src-sym">) </span>= <span class="src-var">$limit</span><span class="src-sym">;</span></li>
<li><a name="a973"></a>            <span class="src-key">if</span><span class="src-sym">(</span><span class="src-var">$this</span><span class="src-sym">-&gt;</span><span class="src-var">page </span>&lt;= <span class="src-num">0</span><span class="src-sym">) </span><span class="src-str"></span><span class="src-sym">{</span></span></li>
<li><a name="a974"></a></span><span class="src-str">                <span class="src-var">$this</span></span><span class="src-sym">-&gt;</span><span class="src-var">page </span>= <span class="src-num">1</span><span class="src-sym">;</span></li>
<li><a name="a975"></a>            </span><span class="src-str"><span class="src-sym">}</span></span></li>
<li><a name="a976"></a></span><span class="src-str">            <span class="src-comm"># Default for rows_per_page:</span></span></li>
<li><a name="a977"></a></span><span class="src-str"><span class="src-comm"></span>            <span class="src-key">if</span> <span class="src-sym">(</span><span class="src-var">$this</span></span><span class="src-sym">-&gt;</span><span class="src-var">rows_per_page </span>== <span class="src-id">null</span><span class="src-sym">) </span><span class="src-str"></span><span class="src-sym">{</span></span></li>
<li><a name="a978"></a></span><span class="src-str">                <span class="src-var">$this</span></span><span class="src-sym">-&gt;</span><span class="src-var">rows_per_page </span>= <span class="src-var">$this</span><span class="src-sym">-&gt;</span><a href="../PHPonTrax/ActiveRecord.html#var$rows_per_page_default">rows_per_page_default</a><span class="src-sym">;</span></li>
<li><a name="a979"></a>            </span><span class="src-str"><span class="src-sym">}</span></span></li>
<li><a name="a980"></a></span><span class="src-str">            <span class="src-comm"># Set the LIMIT string segment for the SQL in the find_all</span></span></li>
<li><a name="a981"></a></span><span class="src-str"><span class="src-comm"></span>            <span class="src-var">$this</span></span><span class="src-sym">-&gt;</span><span class="src-var">offset </span>= <span class="src-sym">(</span><span class="src-var">$this</span><span class="src-sym">-&gt;</span><span class="src-var">page </span>- <span class="src-num">1</span><span class="src-sym">) </span>* <span class="src-var">$this</span><span class="src-sym">-&gt;</span><span class="src-var">rows_per_page</span><span class="src-sym">;</span></li>
<li><a name="a982"></a>            <span class="src-comm"># mysql 3.23 doesn't support OFFSET</span></li>
<li><a name="a983"></a>            <span class="src-comm">//$limit = &quot;$rows_per_page OFFSET $offset&quot;;</span></li>
<li><a name="a984"></a>            <span class="src-var">$limit </span>= <span class="src-var">$this</span><span class="src-sym">-&gt;</span><span class="src-var">offset</span>.<span class="src-str">&quot;, &quot;</span>.<span class="src-var">$this</span><span class="src-sym">-&gt;</span><span class="src-var">rows_per_page</span><span class="src-sym">;</span></li>
<li><a name="a985"></a>&nbsp;</li>
<li><a name="a986"></a>            <span class="src-comm">//  Remember that we're generating output in pages</span></li>
<li><a name="a987"></a>            <span class="src-comm">//  so $limit needs to be added to the query</span></li>
<li><a name="a988"></a>            <span class="src-var">$set_pages </span>= <span class="src-id">true</span><span class="src-sym">;</span></li>
<li><a name="a989"></a>        </span><span class="src-str"><span class="src-sym">}</span></span></li>
<li><a name="a990"></a>&nbsp;</li>
<li><a name="a991"></a></span><span class="src-str">        <span class="src-comm">//  Test source of SQL for query</span></span></li>
<li><a name="a992"></a></span><span class="src-str"><span class="src-comm"></span>        <span class="src-key">if</span><span class="src-sym">(</span><span class="src-id">stristr</span><span class="src-sym">(</span><span class="src-var">$conditions</span><span class="src-sym">,</span> <span class="src-str">&quot;SELECT&quot;</span><span class="src-sym">))</span> <span class="src-sym">{</span></span></li>
<li><a name="a993"></a>&nbsp;</li>
<li><a name="a994"></a></span><span class="src-str">            <span class="src-comm">//  SQL completely specified in argument so use it as is</span></span></li>
<li><a name="a995"></a></span><span class="src-str"><span class="src-comm"></span>            <span class="src-var">$sql</span> = <span class="src-var">$conditions</span><span class="src-sym">;</span></span></li>
<li><a name="a996"></a></span><span class="src-str">        <span class="src-sym">}</span> <span class="src-key">else</span> <span class="src-sym">{</span></span></li>
<li><a name="a997"></a>&nbsp;</li>
<li><a name="a998"></a></span><span class="src-str">            <span class="src-comm">//  SQL will be built from specifications in argument</span></span></li>
<li><a name="a999"></a></span><span class="src-str"><span class="src-comm"></span>            <span class="src-var">$sql</span>  = <span class="src-str">&quot;SELECT * FROM &quot;</span>.<span class="src-var">$this</span></span><span class="src-sym">-&gt;</span><a href="../PHPonTrax/ActiveRecord.html#var$table_name">table_name</a>.<span class="src-str">&quot; &quot;</span><span class="src-sym">;</span></li>
<li><a name="a1000"></a>&nbsp;</li>
<li><a name="a1001"></a>            <span class="src-comm">//  If join specified, include it</span></li>
<li><a name="a1002"></a>            <span class="src-key">if</span><span class="src-sym">(</span><span class="src-sym">!</span><span class="src-id">is_null</span><span class="src-sym">(</span><span class="src-var">$joins</span><span class="src-sym">)) </span><span class="src-str"></span><span class="src-sym">{</span></span></li>
<li><a name="a1003"></a></span><span class="src-str">                <span class="src-key">if</span><span class="src-sym">(</span><span class="src-id">substr</span><span class="src-sym">(</span><span class="src-var">$joins</span><span class="src-sym">,</span><span class="src-num">0</span><span class="src-sym">,</span><span class="src-num">4</span><span class="src-sym">)</span> != <span class="src-str">&quot;LEFT&quot;</span><span class="src-sym">)</span> <span class="src-var">$sql</span> .= <span class="src-str">&quot;,&quot;</span><span class="src-sym">;</span></span></li>
<li><a name="a1004"></a></span><span class="src-str">                <span class="src-var">$sql</span> .= <span class="src-str">"</span> <span class="src-var">$joins</span> <span class="src-str">"</span><span class="src-sym">;</span></span></li>
<li><a name="a1005"></a></span><span class="src-str">            <span class="src-sym">}</span></span></li>
<li><a name="a1006"></a>&nbsp;</li>
<li><a name="a1007"></a></span><span class="src-str">            <span class="src-comm">//  If conditions specified, include them</span></span></li>
<li><a name="a1008"></a></span><span class="src-str"><span class="src-comm"></span>            <span class="src-key">if</span><span class="src-sym">(</span><span class="src-sym">!</span><span class="src-id">is_null</span><span class="src-sym">(</span><span class="src-var">$conditions</span><span class="src-sym">))</span> <span class="src-sym">{</span></span></li>
<li><a name="a1009"></a></span><span class="src-str">                <span class="src-var">$sql</span> .= <span class="src-str">"</span><span class="src-id">WHERE</span> <span class="src-var">$conditions</span> <span class="src-str">"</span><span class="src-sym">;</span></span></li>
<li><a name="a1010"></a></span><span class="src-str">            <span class="src-sym">}</span></span></li>
<li><a name="a1011"></a>&nbsp;</li>
<li><a name="a1012"></a></span><span class="src-str">            <span class="src-comm">//  If ordering specified, include it</span></span></li>
<li><a name="a1013"></a></span><span class="src-str"><span class="src-comm"></span>            <span class="src-key">if</span><span class="src-sym">(</span><span class="src-sym">!</span><span class="src-id">is_null</span><span class="src-sym">(</span><span class="src-var">$orderings</span><span class="src-sym">))</span> <span class="src-sym">{</span></span></li>
<li><a name="a1014"></a></span><span class="src-str">                <span class="src-var">$sql</span> .= <span class="src-str">"</span><span class="src-id">ORDER</span> <span class="src-id">BY</span> <span class="src-var">$orderings</span> <span class="src-str">"</span><span class="src-sym">;</span></span></li>
<li><a name="a1015"></a></span><span class="src-str">            <span class="src-sym">}</span></span></li>
<li><a name="a1016"></a>&nbsp;</li>
<li><a name="a1017"></a></span><span class="src-str">            <span class="src-comm">//  If limit specified, divide into pages</span></span></li>
<li><a name="a1018"></a></span><span class="src-str"><span class="src-comm"></span>            <span class="src-key">if</span><span class="src-sym">(</span><span class="src-sym">!</span><span class="src-id">is_null</span><span class="src-sym">(</span><span class="src-var">$limit</span><span class="src-sym">))</span> <span class="src-sym">{</span></span></li>
<li><a name="a1019"></a></span><span class="src-str">                <span class="src-comm">//  FIXME: Isn't the  second test redundant?</span></span></li>
<li><a name="a1020"></a></span><span class="src-str"><span class="src-comm"></span>                <span class="src-key">if</span><span class="src-sym">(</span><span class="src-var">$set_pages</span><span class="src-sym">)</span> <span class="src-sym">{</span></span></li>
<li><a name="a1021"></a>&nbsp;</li>
<li><a name="a1022"></a></span><span class="src-str">                    <span class="src-comm">//  Send query to database</span></span></li>
<li><a name="a1023"></a></span><span class="src-str"><span class="src-comm"></span>                    <span class="src-comm">//echo &quot;query: $sql\n&quot;;</span></span></li>
<li><a name="a1024"></a></span><span class="src-str"><span class="src-comm"></span>                    <span class="src-key">if</span><span class="src-sym">(</span><span class="src-var">$this</span></span><span class="src-sym">-&gt;</span><a href="../PHPonTrax/ActiveRecord.html#methodis_error">is_error</a><span class="src-sym">(</span><span class="src-var">$rs </span>= <span class="src-var">$this</span><span class="src-sym">-&gt;</span><a href="../PHPonTrax/ActiveRecord.html#methodquery">query</a><span class="src-sym">(</span><span class="src-var">$sql</span><span class="src-sym">))) </span><span class="src-str"></span><span class="src-sym">{</span></span></li>
<li><a name="a1025"></a>&nbsp;</li>
<li><a name="a1026"></a></span><span class="src-str">                        <span class="src-comm">//  Error returned, throw error exception</span></span></li>
<li><a name="a1027"></a></span><span class="src-str"><span class="src-comm"></span>                        <span class="src-var">$this</span></span><span class="src-sym">-&gt;</span><a href="../PHPonTrax/ActiveRecord.html#methodraise">raise</a><span class="src-sym">(</span><span class="src-var">$rs</span><span class="src-sym">-&gt;</span><span class="src-id">getMessage</span><span class="src-sym">(</span><span class="src-sym">))</span><span class="src-sym">;</span></li>
<li><a name="a1028"></a>                        <span class="src-comm">//  Execution doesn't return here</span></li>
<li><a name="a1029"></a>                    </span><span class="src-str"><span class="src-sym">}</span> <span class="src-key">else</span> <span class="src-sym">{</span></span></li>
<li><a name="a1030"></a>&nbsp;</li>
<li><a name="a1031"></a></span><span class="src-str">                        <span class="src-comm"># Set number of total pages in result set </span></span></li>
<li><a name="a1032"></a></span><span class="src-str"><span class="src-comm"></span>                        <span class="src-comm"># without the LIMIT  </span></span></li>
<li><a name="a1033"></a></span><span class="src-str"><span class="src-comm"></span>                        <span class="src-key">if</span><span class="src-sym">(</span><span class="src-var">$count</span> = <span class="src-var">$rs</span></span><span class="src-sym">-&gt;</span><span class="src-id">numRows</span><span class="src-sym">(</span><span class="src-sym">))</span></li>
<li><a name="a1034"></a>                            <span class="src-var">$this</span><span class="src-sym">-&gt;</span><span class="src-var">pages </span>= <span class="src-sym">(</span></li>
<li><a name="a1035"></a>                               <span class="src-sym">(</span><span class="src-var">$count </span>% <span class="src-var">$this</span><span class="src-sym">-&gt;</span><span class="src-var">rows_per_page</span><span class="src-sym">) </span>== <span class="src-num">0</span><span class="src-sym">)</span></li>
<li><a name="a1036"></a>                                ? <span class="src-var">$count </span>/ <span class="src-var">$this</span><span class="src-sym">-&gt;</span></li>
<li><a name="a1036"></a><span class="src-var">rows_per_page</span></li>
<li><a name="a1037"></a>                                : <span class="src-id">floor</span><span class="src-sym">(</span><span class="src-var">$count </span>/ <span class="src-var">$this</span><span class="src-sym">-&gt;</span><span class="src-var">rows_per_page</span><span class="src-sym">) </span>+ <span class="src-num">1</span><span class="src-sym">;</span></li>
<li><a name="a1038"></a>                    </span><span class="src-str"><span class="src-sym">}</span></span></li>
<li><a name="a1039"></a></span><span class="src-str">                <span class="src-sym">}</span></span></li>
<li><a name="a1040"></a></span><span class="src-str">                <span class="src-var">$sql</span> .= <span class="src-str">"</span><span class="src-id">LIMIT</span> <span class="src-var">$limit</span><span class="src-str">"</span><span class="src-sym">;</span></span></li>
<li><a name="a1041"></a></span><span class="src-str">            <span class="src-sym">}</span></span></li>
<li><a name="a1042"></a></span><span class="src-str">        <span class="src-sym">}</span></span></li>
<li><a name="a1043"></a>&nbsp;</li>
<li><a name="a1044"></a></span><span class="src-str">        <span class="src-comm">//echo &quot;ActiveRecord::find_all() - sql: $sql\n&lt;br&gt;&quot;;</span></span></li>
<li><a name="a1045"></a></span><span class="src-str"><span class="src-comm"></span>        <span class="src-comm">//echo &quot;query: $sql\n&quot;;</span></span></li>
<li><a name="a1046"></a></span><span class="src-str"><span class="src-comm"></span>        <span class="src-key">if</span><span class="src-sym">(</span><span class="src-var">$this</span></span><span class="src-sym">-&gt;</span><a href="../PHPonTrax/ActiveRecord.html#methodis_error">is_error</a><span class="src-sym">(</span><span class="src-var">$rs </span>= <span class="src-var">$this</span><span class="src-sym">-&gt;</span><a href="../PHPonTrax/ActiveRecord.html#methodquery">query</a><span class="src-sym">(</span><span class="src-var">$sql</span><span class="src-sym">))) </span><span class="src-str"></span><span class="src-sym">{</span></span></li>
<li><a name="a1047"></a></span><span class="src-str">            <span class="src-var">$this</span></span><span class="src-sym">-&gt;</span><a href="../PHPonTrax/ActiveRecord.html#methodraise">raise</a><span class="src-sym">(</span><span class="src-var">$rs</span><span class="src-sym">-&gt;</span><span class="src-id">getMessage</span><span class="src-sym">(</span><span class="src-sym">))</span><span class="src-sym">;</span></li>
<li><a name="a1048"></a>        </span><span class="src-str"><span class="src-sym">}</span></span></li>
<li><a name="a1049"></a>&nbsp;</li>
<li><a name="a1050"></a></span><span class="src-str">        <span class="src-var">$objects</span> = <span class="src-key">array</span><span class="src-sym">(</span><span class="src-sym">)</span><span class="src-sym">;</span></span></li>
<li><a name="a1051"></a></span><span class="src-str">        <span class="src-key">while</span><span class="src-sym">(</span><span class="src-var">$row</span> = <span class="src-var">$rs</span></span><span class="src-sym">-&gt;</span><span class="src-id">fetchRow</span><span class="src-sym">(</span><span class="src-sym">)) </span><span class="src-str"></span><span class="src-sym">{</span></span></li>
<li><a name="a1052"></a></span><span class="src-str">            <span class="src-comm">#$class = get_class($this);</span></span></li>
<li><a name="a1053"></a></span><span class="src-str"><span class="src-comm"></span>            <span class="src-var">$class</span> = <span class="src-id">Inflector</span><span class="src-sym">::</span><span class="src-id">classify</span><span class="src-sym">(</span><span class="src-var">$this</span></span><span class="src-sym">-&gt;</span><a href="../PHPonTrax/ActiveRecord.html#var$table_name">table_name</a><span class="src-sym">)</span><span class="src-sym">;</span></li>
<li><a name="a1054"></a>            <span class="src-var">$object </span>= <span class="src-key">new </span><span class="src-var">$class</span><span class="src-sym">(</span><span class="src-sym">)</span><span class="src-sym">;</span></li>
<li><a name="a1055"></a>            <span class="src-var">$object</span><span class="src-sym">-&gt;</span><span class="src-id">new_record </span>= <span class="src-id">false</span><span class="src-sym">;</span></li>
<li><a name="a1056"></a>            <span class="src-key">foreach</span><span class="src-sym">(</span><span class="src-var">$row </span><span class="src-key">as </span><span class="src-var">$field </span>=&gt; <span class="src-var">$val</span><span class="src-sym">) </span><span class="src-str"></span><span class="src-sym">{</span></span></li>
<li><a name="a1057"></a></span><span class="src-str">                <span class="src-var">$object</span></span><span class="src-sym">-&gt;</span><span class="src-var">$field </span>= <span class="src-var">$val</span><span class="src-sym">;</span></li>
<li><a name="a1058"></a>                <span class="src-key">if</span><span class="src-sym">(</span><span class="src-var">$field </span>== <span class="src-var">$this</span><span class="src-sym">-&gt;</span><a href="../PHPonTrax/ActiveRecord.html#var$index_on">index_on</a><span class="src-sym">) </span><span class="src-str"></span><span class="src-sym">{</span></span></li>
<li><a name="a1059"></a></span><span class="src-str">                    <span class="src-var">$objects_key</span> = <span class="src-var">$val</span><span class="src-sym">;</span></span></li>
<li><a name="a1060"></a></span><span class="src-str">                <span class="src-sym">}</span></span></li>
<li><a name="a1061"></a></span><span class="src-str">            <span class="src-sym">}</span></span></li>
<li><a name="a1062"></a></span><span class="src-str">            <span class="src-var">$objects</span><span class="src-sym">[</span><span class="src-var">$objects_key</span><span class="src-sym">]</span> = <span class="src-var">$object</span><span class="src-sym">;</span></span></li>
<li><a name="a1063"></a></span><span class="src-str">            unset<span class="src-sym">(</span><span class="src-var">$object</span><span class="src-sym">)</span><span class="src-sym">;</span></span></li>
<li><a name="a1064"></a></span><span class="src-str">            unset<span class="src-sym">(</span><span class="src-var">$objects_key</span><span class="src-sym">)</span><span class="src-sym">;</span></span></li>
<li><a name="a1065"></a></span><span class="src-str">        <span class="src-sym">}</span></span></li>
<li><a name="a1066"></a></span><span class="src-str">        <span class="src-key">return</span> <span class="src-var">$objects</span><span class="src-sym">;</span></span></li>
<li><a name="a1067"></a></span><span class="src-str">    <span class="src-sym">}</span></span></li>
<li><a name="a1068"></a>&nbsp;</li>
<li><a name="a1069"></a></span><span class="src-str">    /**</span></li>
<li><a name="a1070"></a></span><span class="src-str">     *  Find row(s) with specified value(s)</span></li>
<li><a name="a1071"></a></span><span class="src-str">     *</span></li>
<li><a name="a1072"></a></span><span class="src-str">     *  Find all the rows in the table which match the argument $id.</span></li>
<li><a name="a1073"></a></span><span class="src-str">     *  Return zero or more objects of the same class as this</span></li>
<li><a name="a1074"></a></span><span class="src-str">     *  class representing the rows that matched the argument.</span></li>
<li><a name="a1075"></a></span><span class="src-str">     *  @param mixed[] $id  If $id is an array then a query will be</span></li>
<li><a name="a1076"></a></span><span class="src-str">     *    generated selecting all of the array values in column &quot;id&quot;.</span></li>
<li><a name="a1077"></a></span><span class="src-str">     *    If $id is a string containing &quot;=&quot; then the string value of</span></li>
<li><a name="a1078"></a></span><span class="src-str">     *    $id will be inserted in a WHERE clause in the query.  If $id</span></li>
<li><a name="a1079"></a></span><span class="src-str">     *    is a scalar not containing &quot;=&quot; then a query will be generated </span></li>
<li><a name="a1080"></a></span><span class="src-str">     *    selecting the first row WHERE id = '$id'.</span></li>
<li><a name="a1081"></a></span><span class="src-str">     *    &lt;b&gt;NOTE&lt;/b&gt; The column name &quot;id&quot; is used regardless of the</span></li>
<li><a name="a1082"></a></span><span class="src-str">     *    value of {@link $primary_keys}.  Therefore if you need to</span></li>
<li><a name="a1083"></a></span><span class="src-str">     *    select based on some column other than &quot;id&quot;, you must pass a</span></li>
<li><a name="a1084"></a></span><span class="src-str">     *    string argument ready to insert in the SQL SELECT.</span></li>
<li><a name="a1085"></a></span><span class="src-str">     *  @param string $orderings Argument to &quot;ORDER BY&quot; in query.</span></li>
<li><a name="a1086"></a></span><span class="src-str">     *    If specified, the query will include &quot;ORDER BY</span></li>
<li><a name="a1087"></a></span><span class="src-str">     *    $orderings&quot;. If omitted, no ordering will be applied.</span></li>
<li><a name="a1088"></a></span><span class="src-str">     *  @param integer[] $limit Page, rows per page???</span></li>
<li><a name="a1089"></a></span><span class="src-str">     *  @param string $joins ???</span></li>
<li><a name="a1090"></a></span><span class="src-str">     *  @todo Document the $limit and $joins parameters</span></li>
<li><a name="a1091"></a></span><span class="src-str">     *  @uses find_all()</span></li>
<li><a name="a1092"></a></span><span class="src-str">     *  @uses find_first()</span></li>
<li><a name="a1093"></a></span><span class="src-str">     *  @return mixed Results of query.  If $id was a scalar then the</span></li>
<li><a name="a1094"></a></span><span class="src-str">     *    result is an object of the same class as this class and</span></li>
<li><a name="a1095"></a></span><span class="src-str">     *    matching $id conditions, or if no row matched the result is</span></li>
<li><a name="a1096"></a></span><span class="src-str">     *    null. </span></li>
<li><a name="a1097"></a></span><span class="src-str">     *</span></li>
<li><a name="a1098"></a></span><span class="src-str">     *    If $id was an array then the result is an array containing</span></li>
<li><a name="a1099"></a></span><span class="src-str">     *    objects of the same class as this class and matching the</span></li>
<li><a name="a1100"></a></span><span class="src-str">     *    conditions set by $id.  If no rows matched, the array is</span></li>
<li><a name="a1101"></a></span><span class="src-str">     *    empty.</span></li>
<li><a name="a1102"></a></span><span class="src-str">     *  @throws {@link ActiveRecordError}</span></li>
<li><a name="a1103"></a></span><span class="src-str">     */</span></li>
<li><a name="a1104"></a></span><span class="src-str">    <span class="src-key">function</span> <span class="src-id">find</span><span class="src-sym">(</span><span class="src-var">$id</span><span class="src-sym">,</span> <span class="src-var">$orderings</span> = <span class="src-id">null</span><span class="src-sym">,</span> <span class="src-var">$limit</span> = <span class="src-id">null</span><span class="src-sym">,</span> <span class="src-var">$joins</span> = <span class="src-id">null</span><span class="src-sym">)</span> <span class="src-sym">{</span></span></li>
<li><a name="a1105"></a></span><span class="src-str">        <span class="src-key">if</span><span class="src-sym">(</span><span class="src-id">is_array</span><span class="src-sym">(</span><span class="src-var">$id</span><span class="src-sym">))</span> <span class="src-sym">{</span></span></li>
<li><a name="a1106"></a></span><span class="src-str">            <span class="src-var">$conditions</span> = <span class="src-str">&quot;id IN(&quot;</span>.<span class="src-id">implode</span><span class="src-sym">(</span><span class="src-str">&quot;,&quot;</span><span class="src-sym">,</span><span class="src-var">$id</span><span class="src-sym">)</span>.<span class="src-str">&quot;)&quot;</span><span class="src-sym">;</span></span></li>
<li><a name="a1107"></a></span><span class="src-str">        <span class="src-sym">}</span> <span class="src-key">elseif</span><span class="src-sym">(</span><span class="src-id">stristr</span><span class="src-sym">(</span><span class="src-var">$id</span><span class="src-sym">,</span><span class="src-str">&quot;=&quot;</span><span class="src-sym">))</span> <span class="src-sym">{</span> <span class="src-comm"># has an = so must be a where clause</span></span></li>
<li><a name="a1108"></a></span><span class="src-str"><span class="src-comm"></span>            <span class="src-var">$conditions</span> = <span class="src-var">$id</span><span class="src-sym">;</span></span></li>
<li><a name="a1109"></a></span><span class="src-str">        <span class="src-sym">}</span> <span class="src-key">else</span> <span class="src-sym">{</span></span></li>
<li><a name="a1110"></a></span><span class="src-str">            <span class="src-var">$conditions</span> = <span class="src-str">"</span><span class="src-id">id</span>='<span class="src-var">$id</span>'<span class="src-str">"</span><span class="src-sym">;</span></span></li>
<li><a name="a1111"></a></span><span class="src-str">        <span class="src-sym">}</span></span></li>
<li><a name="a1112"></a>&nbsp;</li>
<li><a name="a1113"></a></span><span class="src-str">        <span class="src-key">if</span><span class="src-sym">(</span><span class="src-id">is_array</span><span class="src-sym">(</span><span class="src-var">$id</span><span class="src-sym">))</span> <span class="src-sym">{</span></span></li>
<li><a name="a1114"></a></span><span class="src-str">            <span class="src-key">return</span> <span class="src-var">$this</span></span><span class="src-sym">-&gt;</span><a href="../PHPonTrax/ActiveRecord.html#methodfind_all">find_all</a><span class="src-sym">(</span><span class="src-var">$conditions</span><span class="src-sym">, </span><span class="src-var">$orderings</span><span class="src-sym">, </span><span class="src-var">$limit</span><span class="src-sym">, </span><span class="src-var">$joins</span><span class="src-sym">)</span><span class="src-sym">;</span></li>
<li><a name="a1115"></a>        </span><span class="src-str"><span class="src-sym">}</span> <span class="src-key">else</span> <span class="src-sym">{</span></span></li>
<li><a name="a1116"></a></span><span class="src-str">            <span class="src-key">return</span> <span class="src-var">$this</span></span><span class="src-sym">-&gt;</span><a href="../PHPonTrax/ActiveRecord.html#methodfind_first">find_first</a><span class="src-sym">(</span><span class="src-var">$conditions</span><span class="src-sym">, </span><span class="src-var">$orderings</span><span class="src-sym">, </span><span class="src-var">$limit</span><span class="src-sym">, </span><span class="src-var">$joins</span><span class="src-sym">)</span><span class="src-sym">;</span></li>
<li><a name="a1117"></a>        </span><span class="src-str"><span class="src-sym">}</span></span></li>
<li><a name="a1118"></a></span><span class="src-str">    <span class="src-sym">}</span></span></li>
<li><a name="a1119"></a>&nbsp;</li>
<li><a name="a1120"></a></span><span class="src-str">    /**</span></li>
<li><a name="a1121"></a></span><span class="src-str">     *  Return first row selected by $conditions</span></li>
<li><a name="a1122"></a></span><span class="src-str">     *</span></li>
<li><a name="a1123"></a></span><span class="src-str">     *  If no rows match, null is returned.</span></li>
<li><a name="a1124"></a></span><span class="src-str">     *  @param string $conditions SQL to use in the query.  If</span></li>
<li><a name="a1125"></a></span><span class="src-str">     *    $conditions contains &quot;SELECT&quot;, then $orderings, $limit and</span></li>
<li><a name="a1126"></a></span><span class="src-str">     *    $joins are ignored and the query is completely specified by</span></li>
<li><a name="a1127"></a></span><span class="src-str">     *    $conditions.  If $conditions is omitted or does not contain</span></li>
<li><a name="a1128"></a></span><span class="src-str">     *    &quot;SELECT&quot;, &quot;SELECT * FROM&quot; will be used.  If $conditions is</span></li>
<li><a name="a1129"></a></span><span class="src-str">     *    specified and does not contain &quot;SELECT&quot;, the query will</span></li>
<li><a name="a1130"></a></span><span class="src-str">     *    include &quot;WHERE $conditions&quot;.  If $conditions is null, the</span></li>
<li><a name="a1131"></a></span><span class="src-str">     *    entire table is returned.</span></li>
<li><a name="a1132"></a></span><span class="src-str">     *  @param string $orderings Argument to &quot;ORDER BY&quot; in query.</span></li>
<li><a name="a1133"></a></span><span class="src-str">     *    If specified, the query will include</span></li>
<li><a name="a1134"></a></span><span class="src-str">     *    &quot;ORDER BY $orderings&quot;. If omitted, no ordering will be</span></li>
<li><a name="a1135"></a></span><span class="src-str">     *    applied.  </span></li>
<li><a name="a1136"></a></span><span class="src-str">     *  FIXME This parameter doesn't seem to make sense</span></li>
<li><a name="a1137"></a></span><span class="src-str">     *  @param integer[] $limit Page, rows per page??? @todo Document this parameter</span></li>
<li><a name="a1138"></a></span><span class="src-str">     *  FIXME This parameter doesn't seem to make sense</span></li>
<li><a name="a1139"></a></span><span class="src-str">     *  @param string $joins ??? @todo Document this parameter</span></li>
<li><a name="a1140"></a></span><span class="src-str">     *  @uses find_all()</span></li>
<li><a name="a1141"></a></span><span class="src-str">     *  @return mixed An object of the same class as this class and</span></li>
<li><a name="a1142"></a></span><span class="src-str">     *    matching $conditions, or null if none did.</span></li>
<li><a name="a1143"></a></span><span class="src-str">     *  @throws {@link ActiveRecordError}</span></li>
<li><a name="a1144"></a></span><span class="src-str">     */</span></li>
<li><a name="a1145"></a></span><span class="src-str">    <span class="src-key">function</span> <span class="src-id">find_first</span><span class="src-sym">(</span><span class="src-var">$conditions</span><span class="src-sym">,</span> <span class="src-var">$orderings</span> = <span class="src-id">null</span><span class="src-sym">,</span> <span class="src-var">$limit</span> = <span class="src-id">null</span><span class="src-sym">,</span> <span class="src-var">$joins</span> = <span class="src-id">null</span><span class="src-sym">)</span> <span class="src-sym">{</span></span></li>
<li><a name="a1146"></a></span><span class="src-str">        <span class="src-var">$result</span> = <span class="src-var">$this</span></span><span class="src-sym">-&gt;</span><a href="../PHPonTrax/ActiveRecord.html#methodfind_all">find_all</a><span class="src-sym">(</span><span class="src-var">$conditions</span><span class="src-sym">, </span><span class="src-var">$orderings</span><span class="src-sym">, </span><span class="src-var">$limit</span><span class="src-sym">, </span><span class="src-var">$joins</span><span class="src-sym">)</span><span class="src-sym">;</span></li>
<li><a name="a1147"></a>        <span class="src-key">return </span><span class="src-sym">@</span><span class="src-id">current</span><span class="src-sym">(</span><span class="src-var">$result</span><span class="src-sym">)</span><span class="src-sym">;</span></li>
<li><a name="a1148"></a>    </span><span class="src-str"><span class="src-sym">}</span></span></li>
<li><a name="a1149"></a>&nbsp;</li>
<li><a name="a1150"></a></span><span class="src-str">    /**</span></li>
<li><a name="a1151"></a></span><span class="src-str">     *  Return all the rows selected by the SQL argument</span></li>
<li><a name="a1152"></a></span><span class="src-str">     *</span></li>
<li><a name="a1153"></a></span><span class="src-str">     *  If no rows match, an empty array is returned.</span></li>
<li><a name="a1154"></a></span><span class="src-str">     *  @param string $sql SQL to use in the query.</span></li>
<li><a name="a1155"></a></span><span class="src-str">     */</span></li>
<li><a name="a1156"></a></span><span class="src-str">    <span class="src-key">function</span> <span class="src-id">find_by_sql</span><span class="src-sym">(</span><span class="src-var">$sql</span><span class="src-sym">)</span> <span class="src-sym">{</span></span></li>
<li><a name="a1157"></a></span><span class="src-str">        <span class="src-key">return</span> <span class="src-var">$this</span></span><span class="src-sym">-&gt;</span><a href="../PHPonTrax/ActiveRecord.html#methodfind_all">find_all</a><span class="src-sym">(</span><span class="src-var">$sql</span><span class="src-sym">)</span><span class="src-sym">;</span></li>
<li><a name="a1158"></a>    </span><span class="src-str"><span class="src-sym">}</span></span></li>
<li><a name="a1159"></a>&nbsp;</li>
<li><a name="a1160"></a></span><span class="src-str">    /**</span></li>
<li><a name="a1161"></a></span><span class="src-str">     *  Reloads the attributes of this object from the database.</span></li>
<li><a name="a1162"></a></span><span class="src-str">     *  @uses get_primary_key_conditions()</span></li>
<li><a name="a1163"></a></span><span class="src-str">     *  @todo Document this API</span></li>
<li><a name="a1164"></a></span><span class="src-str">     */</span></li>
<li><a name="a1165"></a></span><span class="src-str">    <span class="src-key">function</span> <span class="src-id">reload</span><span class="src-sym">(</span><span class="src-var">$conditions</span> = <span class="src-id">null</span><span class="src-sym">)</span> <span class="src-sym">{</span></span></li>
<li><a name="a1166"></a></span><span class="src-str">        <span class="src-key">if</span><span class="src-sym">(</span><span class="src-id">is_null</span><span class="src-sym">(</span><span class="src-var">$conditions</span><span class="src-sym">))</span> <span class="src-sym">{</span></span></li>
<li><a name="a1167"></a></span><span class="src-str">            <span class="src-var">$conditions</span> = <span class="src-var">$this</span></span><span class="src-sym">-&gt;</span><a href="../PHPonTrax/ActiveRecord.html#methodget_primary_key_conditions">get_primary_key_conditions</a><span class="src-sym">(</span><span class="src-sym">)</span><span class="src-sym">;</span></li>
<li><a name="a1168"></a>        </span><span class="src-str"><span class="src-sym">}</span></span></li>
<li><a name="a1169"></a></span><span class="src-str">        <span class="src-var">$object</span> = <span class="src-var">$this</span></span><span class="src-sym">-&gt;</span><a href="../PHPonTrax/ActiveRecord.html#methodfind">find</a><span class="src-sym">(</span><span class="src-var">$conditions</span><span class="src-sym">)</span><span class="src-sym">;</span></li>
<li><a name="a1170"></a>        <span class="src-key">if</span><span class="src-sym">(</span><span class="src-id">is_object</span><span class="src-sym">(</span><span class="src-var">$object</span><span class="src-sym">)) </span><span class="src-str"></span><span class="src-sym">{</span></span></li>
<li><a name="a1171"></a></span><span class="src-str">            <span class="src-key">foreach</span><span class="src-sym">(</span><span class="src-var">$object</span> <span class="src-key">as</span> <span class="src-var">$key</span> =&gt; <span class="src-var">$value</span><span class="src-sym">)</span> <span class="src-sym">{</span></span></li>
<li><a name="a1172"></a></span><span class="src-str">                <span class="src-var">$this</span></span><span class="src-sym">-&gt;</span><span class="src-var">$key </span>= <span class="src-var">$value</span><span class="src-sym">;</span></li>
<li><a name="a1173"></a>            </span><span class="src-str"><span class="src-sym">}</span></span></li>
<li><a name="a1174"></a></span><span class="src-str">            <span class="src-key">return</span> <span class="src-id">true</span><span class="src-sym">;</span></span></li>
<li><a name="a1175"></a></span><span class="src-str">        <span class="src-sym">}</span></span></li>
<li><a name="a1176"></a></span><span class="src-str">        <span class="src-key">return</span> <span class="src-id">false</span><span class="src-sym">;</span></span></li>
<li><a name="a1177"></a></span><span class="src-str">    <span class="src-sym">}</span></span></li>
<li><a name="a1178"></a>&nbsp;</li>
<li><a name="a1179"></a></span><span class="src-str">    /**</span></li>
<li><a name="a1180"></a></span><span class="src-str">     *  Loads into current object values from the database.</span></li>
<li><a name="a1181"></a></span><span class="src-str">     */</span></li>
<li><a name="a1182"></a></span><span class="src-str">    <span class="src-key">function</span> <span class="src-id">load</span><span class="src-sym">(</span><span class="src-var">$conditions</span> = <span class="src-id">null</span><span class="src-sym">)</span> <span class="src-sym">{</span></span></li>
<li><a name="a1183"></a></span><span class="src-str">        <span class="src-key">return</span> <span class="src-var">$this</span></span><span class="src-sym">-&gt;</span><a href="../PHPonTrax/ActiveRecord.html#methodreload">reload</a><span class="src-sym">(</span><span class="src-var">$conditions</span><span class="src-sym">)</span><span class="src-sym">;        </span></li>
<li><a name="a1184"></a>    </span><span class="src-str"><span class="src-sym">}</span></span></li>
<li><a name="a1185"></a>&nbsp;</li>
<li><a name="a1186"></a></span><span class="src-str">    /**</span></li>
<li><a name="a1187"></a></span><span class="src-str">     *  @todo Document this API.  What's going on here?  It appears to</span></li>
<li><a name="a1188"></a></span><span class="src-str">     *        either create a row with all empty values, or it tries</span></li>
<li><a name="a1189"></a></span><span class="src-str">     *        to recurse once for each attribute in $attributes.</span></li>
<li><a name="a1190"></a></span><span class="src-str">     *  FIXME: resolve calling sequence</span></li>
<li><a name="a1191"></a></span><span class="src-str">     *  Creates an object, instantly saves it as a record (if the validation permits it).</span></li>
<li><a name="a1192"></a></span><span class="src-str">     *  If the save fails under validations it returns false and $errors array gets set.</span></li>
<li><a name="a1193"></a></span><span class="src-str">     */</span></li>
<li><a name="a1194"></a></span><span class="src-str">    <span class="src-key">function</span> <span class="src-id">create</span><span class="src-sym">(</span><span class="src-var">$attributes</span><span class="src-sym">,</span> <span class="src-var">$dont_validate</span> = <span class="src-id">false</span><span class="src-sym">)</span> <span class="src-sym">{</span></span></li>
<li><a name="a1195"></a></span><span class="src-str">        <span class="src-key">if</span><span class="src-sym">(</span><span class="src-id">is_array</span><span class="src-sym">(</span><span class="src-var">$attributes</span><span class="src-sym">))</span> <span class="src-sym">{</span></span></li>
<li><a name="a1196"></a></span><span class="src-str">            <span class="src-key">foreach</span><span class="src-sym">(</span><span class="src-var">$attributes</span> <span class="src-key">as</span> <span class="src-var">$attr</span><span class="src-sym">)</span> <span class="src-sym">{</span></span></li>
<li><a name="a1197"></a></span><span class="src-str">                <span class="src-var">$this</span></span><span class="src-sym">-&gt;</span><a href="../PHPonTrax/ActiveRecord.html#methodcreate">create</a><span class="src-sym">(</span><span class="src-var">$attr</span><span class="src-sym">, </span><span class="src-var">$dont_validate</span><span class="src-sym">)</span><span class="src-sym">;</span></li>
<li><a name="a1198"></a>            </span><span class="src-str"><span class="src-sym">}</span></span></li>
<li><a name="a1199"></a></span><span class="src-str">        <span class="src-sym">}</span> <span class="src-key">else</span> <span class="src-sym">{</span></span></li>
<li><a name="a1200"></a></span><span class="src-str">            <span class="src-var">$class</span> = <span class="src-id">get_class</span><span class="src-sym">(</span><span class="src-var">$this</span><span class="src-sym">)</span><span class="src-sym">;</span></span></li>
<li><a name="a1201"></a></span><span class="src-str">            <span class="src-var">$object</span> = <span class="src-key">new</span> <span class="src-var">$class</span><span class="src-sym">(</span><span class="src-sym">)</span><span class="src-sym">;</span></span></li>
<li><a name="a1202"></a></span><span class="src-str">            <span class="src-var">$object</span></span><span class="src-sym">-&gt;</span><span class="src-id">save</span><span class="src-sym">(</span><span class="src-var">$attributes</span><span class="src-sym">, </span><span class="src-var">$dont_validate</span><span class="src-sym">)</span><span class="src-sym">;</span></li>
<li><a name="a1203"></a>        </span><span class="src-str"><span class="src-sym">}</span></span></li>
<li><a name="a1204"></a></span><span class="src-str">    <span class="src-sym">}</span></span></li>
<li><a name="a1205"></a>&nbsp;</li>
<li><a name="a1206"></a></span><span class="src-str">    /**</span></li>
<li><a name="a1207"></a></span><span class="src-str">     *  Finds the record from the passed id, instantly saves it with the passed attributes </span></li>
<li><a name="a1208"></a></span><span class="src-str">     *  (if the validation permits it). Returns true on success and false on error.</span></li>
<li><a name="a1209"></a></span><span class="src-str">     *  @todo Document this API</span></li>
<li><a name="a1210"></a></span><span class="src-str">     */</span></li>
<li><a name="a1211"></a></span><span class="src-str">    <span class="src-key">function</span> <span class="src-id">update</span><span class="src-sym">(</span><span class="src-var">$id</span><span class="src-sym">,</span> <span class="src-var">$attributes</span><span class="src-sym">,</span> <span class="src-var">$dont_validate</span> = <span class="src-id">false</span><span class="src-sym">)</span> <span class="src-sym">{</span></span></li>
<li><a name="a1212"></a></span><span class="src-str">        <span class="src-key">if</span><span class="src-sym">(</span><span class="src-id">is_array</span><span class="src-sym">(</span><span class="src-var">$id</span><span class="src-sym">))</span> <span class="src-sym">{</span></span></li>
<li><a name="a1213"></a></span><span class="src-str">            <span class="src-key">foreach</span><span class="src-sym">(</span><span class="src-var">$id</span> <span class="src-key">as</span> <span class="src-var">$update_id</span><span class="src-sym">)</span> <span class="src-sym">{</span></span></li>
<li><a name="a1214"></a></span><span class="src-str">                <span class="src-var">$this</span></span><span class="src-sym">-&gt;</span><a href="../PHPonTrax/ActiveRecord.html#methodupdate">update</a><span class="src-sym">(</span><span class="src-var">$update_id</span><span class="src-sym">, </span><span class="src-var">$attributes</span><span class="src-sym">[</span><span class="src-var">$update_id</span><span class="src-sym">]</span><span class="src-sym">, </span><span class="src-var">$dont_validate</span><span class="src-sym">)</span><span class="src-sym">;</span></li>
<li><a name="a1215"></a>            </span><span class="src-str"><span class="src-sym">}</span></span></li>
<li><a name="a1216"></a></span><span class="src-str">        <span class="src-sym">}</span> <span class="src-key">else</span> <span class="src-sym">{</span></span></li>
<li><a name="a1217"></a></span><span class="src-str">            <span class="src-var">$object</span> = <span class="src-var">$this</span></span><span class="src-sym">-&gt;</span><a href="../PHPonTrax/ActiveRecord.html#methodfind">find</a><span class="src-sym">(</span><span class="src-var">$id</span><span class="src-sym">)</span><span class="src-sym">;</span></li>
<li><a name="a1218"></a>            <span class="src-key">return </span><span class="src-var">$object</span><span class="src-sym">-&gt;</span><span class="src-id">save</span><span class="src-sym">(</span><span class="src-var">$attributes</span><span class="src-sym">, </span><span class="src-var">$dont_validate</span><span class="src-sym">)</span><span class="src-sym">;</span></li>
<li><a name="a1219"></a>        </span><span class="src-str"><span class="src-sym">}</span></span></li>
<li><a name="a1220"></a></span><span class="src-str">    <span class="src-sym">}</span></span></li>
<li><a name="a1221"></a>&nbsp;</li>
<li><a name="a1222"></a></span><span class="src-str">    /**</span></li>
<li><a name="a1223"></a></span><span class="src-str">     *  Updates all records with the SET-part of an SQL update statement in updates and </span></li>
<li><a name="a1224"></a></span><span class="src-str">     *  returns an integer with the number of rows updates. A subset of the records can </span></li>
<li><a name="a1225"></a></span><span class="src-str">     *  be selected by specifying conditions. </span></li>
<li><a name="a1226"></a></span><span class="src-str">     *  Example:</span></li>
<li><a name="a1227"></a></span><span class="src-str">     *    $model-&gt;update_all(&quot;category = 'cooldude', approved = 1&quot;, &quot;author = 'John'&quot;);</span></li>
<li><a name="a1228"></a></span><span class="src-str">     *  @uses is_error()</span></li>
<li><a name="a1229"></a></span><span class="src-str">     *  @uses query()</span></li>
<li><a name="a1230"></a></span><span class="src-str">     *  @throws {@link ActiveRecordError}</span></li>
<li><a name="a1231"></a></span><span class="src-str">     *  @todo Document this API</span></li>
<li><a name="a1232"></a></span><span class="src-str">     */</span></li>
<li><a name="a1233"></a></span><span class="src-str">    <span class="src-key">function</span> <span class="src-id">update_all</span><span class="src-sym">(</span><span class="src-var">$updates</span><span class="src-sym">,</span> <span class="src-var">$conditions</span> = <span class="src-id">null</span><span class="src-sym">)</span> <span class="src-sym">{</span></span></li>
<li><a name="a1234"></a></span><span class="src-str">        <span class="src-var">$sql</span> = <span class="src-str">"</span><span class="src-id">UPDATE</span> <span class="src-var">$this</span></span><span class="src-sym">-&gt;</span><a href="../PHPonTrax/ActiveRecord.html#var$table_name">table_name</a> <span class="src-id">SET </span><span class="src-var">$updates </span><span class="src-id">WHERE </span><span class="src-var">$conditions</span><span class="src-str"></span><span class="src-str">"</span><span class="src-sym">;</span></span></li>
<li><a name="a1235"></a></span><span class="src-str">        <span class="src-var">$result</span> = <span class="src-var">$this</span></span><span class="src-sym">-&gt;</span><a href="../PHPonTrax/ActiveRecord.html#methodquery">query</a><span class="src-sym">(</span><span class="src-var">$sql</span><span class="src-sym">)</span><span class="src-sym">;</span></li>
<li><a name="a1236"></a>        <span class="src-key">if </span><span class="src-sym">(</span><span class="src-var">$this</span><span class="src-sym">-&gt;</span><a href="../PHPonTrax/ActiveRecord.html#methodis_error">is_error</a><span class="src-sym">(</span><span class="src-var">$result</span><span class="src-sym">)) </span><span class="src-str"></span><span class="src-sym">{</span></span></li>
<li><a name="a1237"></a></span><span class="src-str">            <span class="src-var">$this</span></span><span class="src-sym">-&gt;</span><a href="../PHPonTrax/ActiveRecord.html#methodraise">raise</a><span class="src-sym">(</span><span class="src-var">$result</span><span class="src-sym">-&gt;</span><span class="src-id">getMessage</span><span class="src-sym">(</span><span class="src-sym">))</span><span class="src-sym">;</span></li>
<li><a name="a1238"></a>        </span><span class="src-str"><span class="src-sym">}</span> <span class="src-key">else</span> <span class="src-sym">{</span></span></li>
<li><a name="a1239"></a></span><span class="src-str">            <span class="src-key">return</span> <span class="src-id">true</span><span class="src-sym">;</span></span></li>
<li><a name="a1240"></a></span><span class="src-str">        <span class="src-sym">}</span></span></li>
<li><a name="a1241"></a></span><span class="src-str">    <span class="src-sym">}</span></span></li>
<li><a name="a1242"></a>&nbsp;</li>
<li><a name="a1243"></a></span><span class="src-str">    /**</span></li>
<li><a name="a1244"></a></span><span class="src-str">     *  Save without valdiating anything.</span></li>
<li><a name="a1245"></a></span><span class="src-str">     *  @todo Document this API</span></li>
<li><a name="a1246"></a></span><span class="src-str">     */</span></li>
<li><a name="a1247"></a></span><span class="src-str">    <span class="src-key">function</span> <span class="src-id">save_without_validation</span><span class="src-sym">(</span><span class="src-var">$attributes</span> = <span class="src-id">null</span><span class="src-sym">)</span> <span class="src-sym">{</span></span></li>
<li><a name="a1248"></a></span><span class="src-str">        <span class="src-key">return</span> <span class="src-var">$this</span></span><span class="src-sym">-&gt;</span><a href="../PHPonTrax/ActiveRecord.html#methodsave">save</a><span class="src-sym">(</span><span class="src-var">$attributes</span><span class="src-sym">, </span><span class="src-id">true</span><span class="src-sym">)</span><span class="src-sym">;</span></li>
<li><a name="a1249"></a>    </span><span class="src-str"><span class="src-sym">}</span></span></li>
<li><a name="a1250"></a>&nbsp;</li>
<li><a name="a1251"></a></span><span class="src-str">    /**</span></li>
<li><a name="a1252"></a></span><span class="src-str">     *  Create or update a row in the table with specified attributes</span></li>
<li><a name="a1253"></a></span><span class="src-str">     *</span></li>
<li><a name="a1254"></a></span><span class="src-str">     *  @param string[] $attributes List of name =&gt; value pairs giving</span></li>
<li><a name="a1255"></a></span><span class="src-str">     *    name and value of attributes to set.</span></li>
<li><a name="a1256"></a></span><span class="src-str">     *  @param boolean $dont_validate true =&gt; Don't call validation</span></li>
<li><a name="a1257"></a></span><span class="src-str">     *    routines before saving the row.  If false or omitted, all </span></li>
<li><a name="a1258"></a></span><span class="src-str">     *    applicable validation routines are called.</span></li>
<li><a name="a1259"></a></span><span class="src-str">     *  @uses add_record_or_update_record()</span></li>
<li><a name="a1260"></a></span><span class="src-str">     *  @uses update_attributes()</span></li>
<li><a name="a1261"></a></span><span class="src-str">     *  @uses valid()</span></li>
<li><a name="a1262"></a></span><span class="src-str">     *  @return boolean</span></li>
<li><a name="a1263"></a></span><span class="src-str">     *          &lt;ul&gt;</span></li>
<li><a name="a1264"></a></span><span class="src-str">     *            &lt;li&gt;true =&gt; row was updated or inserted successfully&lt;/li&gt;</span></li>
<li><a name="a1265"></a></span><span class="src-str">     *            &lt;li&gt;false =&gt; insert failed&lt;/li&gt;</span></li>
<li><a name="a1266"></a></span><span class="src-str">     *          &lt;/ul&gt;</span></li>
<li><a name="a1267"></a></span><span class="src-str">     */</span></li>
<li><a name="a1268"></a></span><span class="src-str">    <span class="src-key">function</span> <span class="src-id">save</span><span class="src-sym">(</span><span class="src-var">$attributes</span> = <span class="src-id">null</span><span class="src-sym">,</span> <span class="src-var">$dont_validate</span> = <span class="src-id">false</span><span class="src-sym">)</span> <span class="src-sym">{</span></span></li>
<li><a name="a1269"></a></span><span class="src-str">        <span class="src-comm">//error_log(&quot;ActiveRecord::save() \$attributes=&quot;</span></span></li>
<li><a name="a1270"></a></span><span class="src-str"><span class="src-comm"></span>        <span class="src-comm">//          . var_export($attributes,true));</span></span></li>
<li><a name="a1271"></a></span><span class="src-str"><span class="src-comm"></span>        <span class="src-key">if</span><span class="src-sym">(</span><span class="src-sym">!</span><span class="src-id">is_null</span><span class="src-sym">(</span><span class="src-var">$attributes</span><span class="src-sym">))</span> <span class="src-sym">{</span></span></li>
<li><a name="a1272"></a></span><span class="src-str">            <span class="src-var">$this</span></span><span class="src-sym">-&gt;</span><a href="../PHPonTrax/ActiveRecord.html#methodupdate_attributes">update_attributes</a><span class="src-sym">(</span><span class="src-var">$attributes</span><span class="src-sym">)</span><span class="src-sym">;</span></li>
<li><a name="a1273"></a>        </span><span class="src-str"><span class="src-sym">}</span></span></li>
<li><a name="a1274"></a></span><span class="src-str">        <span class="src-key">if</span> <span class="src-sym">(</span><span class="src-var">$dont_validate</span> || <span class="src-var">$this</span></span><span class="src-sym">-&gt;</span><a href="../PHPonTrax/ActiveRecord.html#methodvalid">valid</a><span class="src-sym">(</span><span class="src-sym">)) </span><span class="src-str"></span><span class="src-sym">{</span></span></li>
<li><a name="a1275"></a></span><span class="src-str">            <span class="src-key">return</span> <span class="src-var">$this</span></span><span class="src-sym">-&gt;</span><a href="../PHPonTrax/ActiveRecord.html#methodadd_record_or_update_record">add_record_or_update_record</a><span class="src-sym">(</span><span class="src-sym">)</span><span class="src-sym">;</span></li>
<li><a name="a1276"></a>        </span><span class="src-str"><span class="src-sym">}</span> <span class="src-key">else</span> <span class="src-sym">{</span></span></li>
<li><a name="a1277"></a></span><span class="src-str">            <span class="src-key">return</span> <span class="src-id">false</span><span class="src-sym">;</span></span></li>
<li><a name="a1278"></a></span><span class="src-str">        <span class="src-sym">}</span></span></li>
<li><a name="a1279"></a></span><span class="src-str">    <span class="src-sym">}</span></span></li>
<li><a name="a1280"></a>&nbsp;</li>
<li><a name="a1281"></a></span><span class="src-str">    /**</span></li>
<li><a name="a1282"></a></span><span class="src-str">     *  Create or update a row in the table</span></li>
<li><a name="a1283"></a></span><span class="src-str">     *</span></li>
<li><a name="a1284"></a></span><span class="src-str">     *  If this object represents a new row in the table, insert it.</span></li>
<li><a name="a1285"></a></span><span class="src-str">     *  Otherwise, update the exiting row.  before_?() and after_?()</span></li>
<li><a name="a1286"></a></span><span class="src-str">     *  routines will be called depending on whether the row is new.</span></li>
<li><a name="a1287"></a></span><span class="src-str">     *  @uses add_record()</span></li>
<li><a name="a1288"></a></span><span class="src-str">     *  @uses after_create()</span></li>
<li><a name="a1289"></a></span><span class="src-str">     *  @uses after_update()</span></li>
<li><a name="a1290"></a></span><span class="src-str">     *  @uses before_create()</span></li>
<li><a name="a1291"></a></span><span class="src-str">     *  @uses before_save()</span></li>
<li><a name="a1292"></a></span><span class="src-str">     *  @uses $new_record</span></li>
<li><a name="a1293"></a></span><span class="src-str">     *  @uses update_record()</span></li>
<li><a name="a1294"></a></span><span class="src-str">     *  @return boolean</span></li>
<li><a name="a1295"></a></span><span class="src-str">     *          &lt;ul&gt;</span></li>
<li><a name="a1296"></a></span><span class="src-str">     *            &lt;li&gt;true =&gt; row was updated or inserted successfully&lt;/li&gt;</span></li>
<li><a name="a1297"></a></span><span class="src-str">     *            &lt;li&gt;false =&gt; insert failed&lt;/li&gt;</span></li>
<li><a name="a1298"></a></span><span class="src-str">     *          &lt;/ul&gt;</span></li>
<li><a name="a1299"></a></span><span class="src-str">     */</span></li>
<li><a name="a1300"></a></span><span class="src-str">    <span class="src-key">private</span> <span class="src-key">function</span> <span class="src-id">add_record_or_update_record</span><span class="src-sym">(</span><span class="src-sym">)</span> <span class="src-sym">{</span> </span></li>
<li><a name="a1301"></a></span><span class="src-str">        <span class="src-comm">//error_log('add_record_or_update_record()');</span></span></li>
<li><a name="a1302"></a></span><span class="src-str"><span class="src-comm"></span>        <span class="src-var">$this</span></span><span class="src-sym">-&gt;</span><a href="../PHPonTrax/ActiveRecord.html#methodbefore_save">before_save</a><span class="src-sym">(</span><span class="src-sym">)</span><span class="src-sym">;</span></li>
<li><a name="a1303"></a>        <span class="src-key">if</span><span class="src-sym">(</span><span class="src-var">$this</span><span class="src-sym">-&gt;</span><a href="../PHPonTrax/ActiveRecord.html#var$new_record">new_record</a><span class="src-sym">) </span><span class="src-str"></span><span class="src-sym">{</span></span></li>
<li><a name="a1304"></a></span><span class="src-str">            <span class="src-var">$this</span></span><span class="src-sym">-&gt;</span><a href="../PHPonTrax/ActiveRecord.html#methodbefore_create">before_create</a><span class="src-sym">(</span><span class="src-sym">)</span><span class="src-sym">;</span></li>
<li><a name="a1305"></a>            <span class="src-var">$result </span>= <span class="src-var">$this</span><span class="src-sym">-&gt;</span><a href="../PHPonTrax/ActiveRecord.html#methodadd_record">add_record</a><span class="src-sym">(</span><span class="src-sym">)</span><span class="src-sym">;   </span></li>
<li><a name="a1306"></a>            <span class="src-var">$this</span><span class="src-sym">-&gt;</span><a href="../PHPonTrax/ActiveRecord.html#methodafter_create">after_create</a><span class="src-sym">(</span><span class="src-sym">)</span><span class="src-sym">; </span></li>
<li><a name="a1307"></a>        </span><span class="src-str"><span class="src-sym">}</span> <span class="src-key">else</span> <span class="src-sym">{</span></span></li>
<li><a name="a1308"></a></span><span class="src-str">            <span class="src-var">$this</span></span><span class="src-sym">-&gt;</span><a href="../PHPonTrax/ActiveRecord.html#methodbefore_update">before_update</a><span class="src-sym">(</span><span class="src-sym">)</span><span class="src-sym">;</span></li>
<li><a name="a1309"></a>            <span class="src-var">$result </span>= <span class="src-var">$this</span><span class="src-sym">-&gt;</span><a href="../PHPonTrax/ActiveRecord.html#methodupdate_record">update_record</a><span class="src-sym">(</span><span class="src-sym">)</span><span class="src-sym">;</span></li>
<li><a name="a1310"></a>            <span class="src-var">$this</span><span class="src-sym">-&gt;</span><a href="../PHPonTrax/ActiveRecord.html#methodafter_update">after_update</a><span class="src-sym">(</span><span class="src-sym">)</span><span class="src-sym">;</span></li>
<li><a name="a1311"></a>        </span><span class="src-str"><span class="src-sym">}</span></span></li>
<li><a name="a1312"></a></span><span class="src-str">        <span class="src-var">$this</span></span><span class="src-sym">-&gt;</span><a href="../PHPonTrax/ActiveRecord.html#methodafter_save">after_save</a><span class="src-sym">(</span><span class="src-sym">)</span><span class="src-sym">;</span></li>
<li><a name="a1313"></a>        <span class="src-key">return </span><span class="src-var">$result</span><span class="src-sym">;</span></li>
<li><a name="a1314"></a>    </span><span class="src-str"><span class="src-sym">}</span></span></li>
<li><a name="a1315"></a>&nbsp;</li>
<li><a name="a1316"></a></span><span class="src-str">    /**</span></li>
<li><a name="a1317"></a></span><span class="src-str">     *  Insert a new row in the table associated with this object</span></li>
<li><a name="a1318"></a></span><span class="src-str">     *</span></li>
<li><a name="a1319"></a></span><span class="src-str">     *  Build an SQL INSERT statement getting the table name from</span></li>
<li><a name="a1320"></a></span><span class="src-str">     *  {@link $table_name}, the column names from {@link</span></li>
<li><a name="a1321"></a></span><span class="src-str">     *  $content_columns} and the values from object variables.</span></li>
<li><a name="a1322"></a></span><span class="src-str">     *  Send the insert to the RDBMS.</span></li>
<li><a name="a1323"></a></span><span class="src-str">     *  FIXME: Shouldn't we be saving the insert ID value as an object</span></li>
<li><a name="a1324"></a></span><span class="src-str">     *  variable $this-&gt;id?</span></li>
<li><a name="a1325"></a></span><span class="src-str">     *  @uses $auto_save_habtm</span></li>
<li><a name="a1326"></a></span><span class="src-str">     *  @uses add_habtm_records()</span></li>
<li><a name="a1327"></a></span><span class="src-str">     *  @uses before_create()</span></li>
<li><a name="a1328"></a></span><span class="src-str">     *  @uses get_insert_id()</span></li>
<li><a name="a1329"></a></span><span class="src-str">     *  @uses is_error()</span></li>
<li><a name="a1330"></a></span><span class="src-str">     *  @uses query()</span></li>
<li><a name="a1331"></a></span><span class="src-str">     *  @uses quoted_attributes()</span></li>
<li><a name="a1332"></a></span><span class="src-str">     *  @uses raise()</span></li>
<li><a name="a1333"></a></span><span class="src-str">     *  @uses $table_name</span></li>
<li><a name="a1334"></a></span><span class="src-str">     *  @return boolean</span></li>
<li><a name="a1335"></a></span><span class="src-str">     *          &lt;ul&gt;</span></li>
<li><a name="a1336"></a></span><span class="src-str">     *            &lt;li&gt;true =&gt; row was inserted successfully&lt;/li&gt;</span></li>
<li><a name="a1337"></a></span><span class="src-str">     *            &lt;li&gt;false =&gt; insert failed&lt;/li&gt;</span></li>
<li><a name="a1338"></a></span><span class="src-str">     *          &lt;/ul&gt;</span></li>
<li><a name="a1339"></a></span><span class="src-str">     *  @throws {@link ActiveRecordError}</span></li>
<li><a name="a1340"></a></span><span class="src-str">     */</span></li>
<li><a name="a1341"></a></span><span class="src-str">    <span class="src-key">private</span> <span class="src-key">function</span> <span class="src-id">add_record</span><span class="src-sym">(</span><span class="src-sym">)</span> <span class="src-sym">{</span></span></li>
<li><a name="a1342"></a></span><span class="src-str">        <span class="src-var">$attributes</span> = <span class="src-var">$this</span></span><span class="src-sym">-&gt;</span><a href="../PHPonTrax/ActiveRecord.html#methodquoted_attributes">quoted_attributes</a><span class="src-sym">(</span><span class="src-sym">)</span><span class="src-sym">;</span></li>
<li><a name="a1343"></a>        <span class="src-var">$fields </span>= <span class="src-sym">@</span><span class="src-id">implode</span><span class="src-sym">(</span><span class="src-str">', '</span><span class="src-sym">, </span><span class="src-id">array_keys</span><span class="src-sym">(</span><span class="src-var">$attributes</span><span class="src-sym">))</span><span class="src-sym">;</span></li>
<li><a name="a1344"></a>        <span class="src-var">$values </span>= <span class="src-sym">@</span><span class="src-id">implode</span><span class="src-sym">(</span><span class="src-str">', '</span><span class="src-sym">, </span><span class="src-id">array_values</span><span class="src-sym">(</span><span class="src-var">$attributes</span><span class="src-sym">))</span><span class="src-sym">;</span></li>
<li><a name="a1345"></a>        <span class="src-var">$sql </span>= </span><span class="src-str"><span class="src-str">"</span><span class="src-id">INSERT</span> <span class="src-id">INTO</span> <span class="src-var">$this</span></span><span class="src-sym">-&gt;</span><a href="../PHPonTrax/ActiveRecord.html#var$table_name">table_name</a> (<span class="src-var">$fields</span>) <span class="src-id">VALUES</span> (<span class="src-var">$values</span>)</span><span class="src-str"><span class="src-str">"</span><span class="src-sym">;</span></span></li>
<li><a name="a1346"></a></span><span class="src-str">        <span class="src-comm">//echo &quot;add_record: SQL: $sql&lt;br&gt;&quot;;</span></span></li>
<li><a name="a1347"></a></span><span class="src-str"><span class="src-comm"></span>        <span class="src-var">$result</span> = <span class="src-var">$this</span></span><span class="src-sym">-&gt;</span><a href="../PHPonTrax/ActiveRecord.html#methodquery">query</a><span class="src-sym">(</span><span class="src-var">$sql</span><span class="src-sym">)</span><span class="src-sym">;</span></li>
<li><a name="a1348"></a>        <span class="src-key">if </span><span class="src-sym">(</span><span class="src-var">$this</span><span class="src-sym">-&gt;</span><a href="../PHPonTrax/ActiveRecord.html#methodis_error">is_error</a><span class="src-sym">(</span><span class="src-var">$result</span><span class="src-sym">)) </span><span class="src-str"></span><span class="src-sym">{</span></span></li>
<li><a name="a1349"></a></span><span class="src-str">            <span class="src-var">$this</span></span><span class="src-sym">-&gt;</span><a href="../PHPonTrax/ActiveRecord.html#methodraise">raise</a><span class="src-sym">(</span><span class="src-var">$results</span><span class="src-sym">-&gt;</span><span class="src-id">getMessage</span><span class="src-sym">(</span><span class="src-sym">))</span><span class="src-sym">;</span></li>
<li><a name="a1350"></a>        </span><span class="src-str"><span class="src-sym">}</span> <span class="src-key">else</span> <span class="src-sym">{</span></span></li>
<li><a name="a1351"></a></span><span class="src-str">            <span class="src-var">$this</span></span><span class="src-sym">-&gt;</span><span class="src-var">id </span>= <span class="src-var">$this</span><span class="src-sym">-&gt;</span><a href="../PHPonTrax/ActiveRecord.html#methodget_insert_id">get_insert_id</a><span class="src-sym">(</span><span class="src-sym">)</span><span class="src-sym">;</span></li>
<li><a name="a1352"></a>            <span class="src-key">if</span><span class="src-sym">(</span><span class="src-var">$this</span><span class="src-sym">-&gt;</span><span class="src-var">id </span>&gt; <span class="src-num">0</span><span class="src-sym">) </span><span class="src-str"></span><span class="src-sym">{</span></span></li>
<li><a name="a1353"></a></span><span class="src-str">                <span class="src-key">if</span><span class="src-sym">(</span><span class="src-var">$this</span></span><span class="src-sym">-&gt;</span><a href="../PHPonTrax/ActiveRecord.html#var$auto_save_habtm">auto_save_habtm</a><span class="src-sym">) </span><span class="src-str"></span><span class="src-sym">{</span></span></li>
<li><a name="a1354"></a></span><span class="src-str">                    <span class="src-var">$habtm_result</span> = <span class="src-var">$this</span></span><span class="src-sym">-&gt;</span><a href="../PHPonTrax/ActiveRecord.html#methodadd_habtm_records">add_habtm_records</a><span class="src-sym">(</span><span class="src-var">$this</span><span class="src-sym">-&gt;</span><span class="src-var">id</span><span class="src-sym">)</span><span class="src-sym">;</span></li>
<li><a name="a1355"></a>                </span><span class="src-str"><span class="src-sym">}</span></span></li>
<li><a name="a1356"></a></span><span class="src-str">                <span class="src-var">$this</span></span><span class="src-sym">-&gt;</span><a href="../PHPonTrax/ActiveRecord.html#methodsave_associations">save_associations</a><span class="src-sym">(</span><span class="src-sym">)</span><span class="src-sym">;</span></li>
<li><a name="a1357"></a>            </span><span class="src-str"><span class="src-sym">}</span>          </span></li>
<li><a name="a1358"></a></span><span class="src-str">            <span class="src-key">return</span> <span class="src-sym">(</span><span class="src-var">$result</span> &amp;&amp; <span class="src-var">$habtm_result</span><span class="src-sym">)</span><span class="src-sym">;</span></span></li>
<li><a name="a1359"></a></span><span class="src-str">        <span class="src-sym">}</span></span></li>
<li><a name="a1360"></a></span><span class="src-str">    <span class="src-sym">}</span></span></li>
<li><a name="a1361"></a>&nbsp;</li>
<li><a name="a1362"></a></span><span class="src-str">    /**</span></li>
<li><a name="a1363"></a></span><span class="src-str">     *  Update the row in the table described by this object</span></li>
<li><a name="a1364"></a></span><span class="src-str">     *</span></li>
<li><a name="a1365"></a></span><span class="src-str">     *  The primary key attributes must exist and have appropriate</span></li>
<li><a name="a1366"></a></span><span class="src-str">     *  non-null values.  If a column is listed in {@link</span></li>
<li><a name="a1367"></a></span><span class="src-str">     *  $content_columns} but no attribute of that name exists, the</span></li>
<li><a name="a1368"></a></span><span class="src-str">     *  column will be set to the null string ''.</span></li>
<li><a name="a1369"></a></span><span class="src-str">     *  @todo Describe habtm automatic update</span></li>
<li><a name="a1370"></a></span><span class="src-str">     *  @uses is_error()</span></li>
<li><a name="a1371"></a></span><span class="src-str">     *  @uses get_updates_sql()</span></li>
<li><a name="a1372"></a></span><span class="src-str">     *  @uses get_primary_key_conditions()</span></li>
<li><a name="a1373"></a></span><span class="src-str">     *  @uses query()</span></li>
<li><a name="a1374"></a></span><span class="src-str">     *  @uses raise()</span></li>
<li><a name="a1375"></a></span><span class="src-str">     *  @uses update_habtm_records()</span></li>
<li><a name="a1376"></a></span><span class="src-str">     *  @return boolean</span></li>
<li><a name="a1377"></a></span><span class="src-str">     *          &lt;ul&gt;</span></li>
<li><a name="a1378"></a></span><span class="src-str">     *            &lt;li&gt;true =&gt; row was updated successfully&lt;/li&gt;</span></li>
<li><a name="a1379"></a></span><span class="src-str">     *            &lt;li&gt;false =&gt; update failed&lt;/li&gt;</span></li>
<li><a name="a1380"></a></span><span class="src-str">     *          &lt;/ul&gt;</span></li>
<li><a name="a1381"></a></span><span class="src-str">     *  @throws {@link ActiveRecordError}</span></li>
<li><a name="a1382"></a></span><span class="src-str">     */</span></li>
<li><a name="a1383"></a></span><span class="src-str">    <span class="src-key">private</span> <span class="src-key">function</span> <span class="src-id">update_record</span><span class="src-sym">(</span><span class="src-sym">)</span> <span class="src-sym">{</span></span></li>
<li><a name="a1384"></a></span><span class="src-str">        <span class="src-comm">//error_log('update_record()');</span></span></li>
<li><a name="a1385"></a></span><span class="src-str"><span class="src-comm"></span>        <span class="src-var">$updates</span> = <span class="src-var">$this</span></span><span class="src-sym">-&gt;</span><a href="../PHPonTrax/ActiveRecord.html#methodget_updates_sql">get_updates_sql</a><span class="src-sym">(</span><span class="src-sym">)</span><span class="src-sym">;</span></li>
<li><a name="a1386"></a>        <span class="src-var">$conditions </span>= <span class="src-var">$this</span><span class="src-sym">-&gt;</span><a href="../PHPonTrax/ActiveRecord.html#methodget_primary_key_conditions">get_primary_key_conditions</a><span class="src-sym">(</span><span class="src-sym">)</span><span class="src-sym">;</span></li>
<li><a name="a1387"></a>        <span class="src-var">$sql </span>= </span><span class="src-str"><span class="src-str">"</span><span class="src-id">UPDATE</span> <span class="src-var">$this</span></span><span class="src-sym">-&gt;</span><a href="../PHPonTrax/ActiveRecord.html#var$table_name">table_name</a> <span class="src-id">SET </span><span class="src-var">$updates </span><span class="src-id">WHERE </span><span class="src-var">$conditions</span><span class="src-str"></span><span class="src-str">"</span><span class="src-sym">;</span></span></li>
<li><a name="a1388"></a></span><span class="src-str">        <span class="src-comm">//error_log(&quot;update_record: SQL: $sql&lt;br&gt;&quot;);</span></span></li>
<li><a name="a1389"></a></span><span class="src-str"><span class="src-comm"></span>        <span class="src-var">$result</span> = <span class="src-var">$this</span></span><span class="src-sym">-&gt;</span><a href="../PHPonTrax/ActiveRecord.html#methodquery">query</a><span class="src-sym">(</span><span class="src-var">$sql</span><span class="src-sym">)</span><span class="src-sym">;</span></li>
<li><a name="a1390"></a>        <span class="src-key">if</span><span class="src-sym">(</span><span class="src-var">$this</span><span class="src-sym">-&gt;</span><a href="../PHPonTrax/ActiveRecord.html#methodis_error">is_error</a><span class="src-sym">(</span><span class="src-var">$result</span><span class="src-sym">)) </span><span class="src-str"></span><span class="src-sym">{</span></span></li>
<li><a name="a1391"></a></span><span class="src-str">            <span class="src-var">$this</span></span><span class="src-sym">-&gt;</span><a href="../PHPonTrax/ActiveRecord.html#methodraise">raise</a><span class="src-sym">(</span><span class="src-var">$results</span><span class="src-sym">-&gt;</span><span class="src-id">getMessage</span><span class="src-sym">(</span><span class="src-sym">))</span><span class="src-sym">;</span></li>
<li><a name="a1392"></a>        </span><span class="src-str"><span class="src-sym">}</span> <span class="src-key">else</span> <span class="src-sym">{</span></span></li>
<li><a name="a1393"></a></span><span class="src-str">            <span class="src-key">if</span><span class="src-sym">(</span><span class="src-var">$this</span></span><span class="src-sym">-&gt;</span><span class="src-var">id </span>&gt; <span class="src-num">0</span><span class="src-sym">) </span><span class="src-str"></span><span class="src-sym">{</span></span></li>
<li><a name="a1394"></a></span><span class="src-str">                <span class="src-key">if</span><span class="src-sym">(</span><span class="src-var">$this</span></span><span class="src-sym">-&gt;</span><a href="../PHPonTrax/ActiveRecord.html#var$auto_save_habtm">auto_save_habtm</a><span class="src-sym">) </span><span class="src-str"></span><span class="src-sym">{</span></span></li>
<li><a name="a1395"></a></span><span class="src-str">                    <span class="src-var">$habtm_result</span> = <span class="src-var">$this</span></span><span class="src-sym">-&gt;</span><a href="../PHPonTrax/ActiveRecord.html#methodupdate_habtm_records">update_habtm_records</a><span class="src-sym">(</span><span class="src-var">$this</span><span class="src-sym">-&gt;</span><span class="src-var">id</span><span class="src-sym">)</span><span class="src-sym">;</span></li>
<li><a name="a1396"></a>                </span><span class="src-str"><span class="src-sym">}</span></span></li>
<li><a name="a1397"></a></span><span class="src-str">                <span class="src-var">$this</span></span><span class="src-sym">-&gt;</span><a href="../PHPonTrax/ActiveRecord.html#methodsave_associations">save_associations</a><span class="src-sym">(</span><span class="src-sym">)</span><span class="src-sym">;</span></li>
<li><a name="a1398"></a>            </span><span class="src-str"><span class="src-sym">}</span>         </span></li>
<li><a name="a1399"></a></span><span class="src-str">            <span class="src-key">return</span> <span class="src-sym">(</span><span class="src-var">$result</span> &amp;&amp; <span class="src-var">$habtm_result</span><span class="src-sym">)</span><span class="src-sym">;</span></span></li>
<li><a name="a1400"></a></span><span class="src-str">        <span class="src-sym">}</span></span></li>
<li><a name="a1401"></a></span><span class="src-str">    <span class="src-sym">}</span></span></li>
<li><a name="a1402"></a></span><span class="src-str">    </span></li>
<li><a name="a1403"></a></span><span class="src-str">    /**</span></li>
<li><a name="a1404"></a></span><span class="src-str">     *  returns the association type if defined in child class or null</span></li>
<li><a name="a1405"></a></span><span class="src-str">     *  @todo Document this API</span></li>
<li><a name="a1406"></a></span><span class="src-str">     *  @todo &lt;b&gt;FIXME:&lt;/b&gt; does the match algorithm match a substring</span></li>
<li><a name="a1407"></a></span><span class="src-str">     *        of what we want to match?</span></li>
<li><a name="a1408"></a></span><span class="src-str">     *  @uses $belongs_to</span></li>
<li><a name="a1409"></a></span><span class="src-str">     *  @uses $has_and_belongs_to_many</span></li>
<li><a name="a1410"></a></span><span class="src-str">     *  @uses $has_many</span></li>
<li><a name="a1411"></a></span><span class="src-str">     *  @uses $has_one</span></li>
<li><a name="a1412"></a></span><span class="src-str">     *  @return mixed Association type, one of the following:</span></li>
<li><a name="a1413"></a></span><span class="src-str">     *  &lt;ul&gt;</span></li>
<li><a name="a1414"></a></span><span class="src-str">     *    &lt;li&gt;&quot;belongs_to&quot;&lt;/li&gt;</span></li>
<li><a name="a1415"></a></span><span class="src-str">     *    &lt;li&gt;&quot;has_and_belongs_to_many&quot;&lt;/li&gt;</span></li>
<li><a name="a1416"></a></span><span class="src-str">     *    &lt;li&gt;&quot;has_many&quot;&lt;/li&gt;</span></li>
<li><a name="a1417"></a></span><span class="src-str">     *    &lt;li&gt;&quot;has_one&quot;&lt;/li&gt;</span></li>
<li><a name="a1418"></a></span><span class="src-str">     *  &lt;/ul&gt;</span></li>
<li><a name="a1419"></a></span><span class="src-str">     *  if an association exists, or null if no association</span></li>
<li><a name="a1420"></a></span><span class="src-str">     */</span></li>
<li><a name="a1421"></a></span><span class="src-str">    <span class="src-key">function</span> <span class="src-id">get_association_type</span><span class="src-sym">(</span><span class="src-var">$association_name</span><span class="src-sym">)</span> <span class="src-sym">{</span></span></li>
<li><a name="a1422"></a></span><span class="src-str">        <span class="src-var">$type</span> = <span class="src-id">null</span><span class="src-sym">;</span></span></li>
<li><a name="a1423"></a></span><span class="src-str">        <span class="src-key">if</span><span class="src-sym">(</span><span class="src-id">is_string</span><span class="src-sym">(</span><span class="src-var">$this</span></span><span class="src-sym">-&gt;</span><a href="../PHPonTrax/ActiveRecord.html#var$has_many">has_many</a><span class="src-sym">)) </span><span class="src-str"></span><span class="src-sym">{</span></span></li>
<li><a name="a1424"></a></span><span class="src-str">            <span class="src-key">if</span><span class="src-sym">(</span><span class="src-id">preg_match</span><span class="src-sym">(</span><span class="src-str">"</span>/<span class="src-var">$association_name</span>/<span class="src-str">"</span><span class="src-sym">,</span> <span class="src-var">$this</span></span><span class="src-sym">-&gt;</span><a href="../PHPonTrax/ActiveRecord.html#var$has_many">has_many</a><span class="src-sym">)) </span><span class="src-str"></span><span class="src-sym">{</span></span></li>
<li><a name="a1425"></a></span><span class="src-str">                <span class="src-var">$type</span> = <span class="src-str">&quot;has_many&quot;</span><span class="src-sym">;</span>    </span></li>
<li><a name="a1426"></a></span><span class="src-str">            <span class="src-sym">}</span></span></li>
<li><a name="a1427"></a></span><span class="src-str">        <span class="src-sym">}</span> <span class="src-key">elseif</span><span class="src-sym">(</span><span class="src-id">is_array</span><span class="src-sym">(</span><span class="src-var">$this</span></span><span class="src-sym">-&gt;</span><a href="../PHPonTrax/ActiveRecord.html#var$has_many">has_many</a><span class="src-sym">)) </span><span class="src-str"></span><span class="src-sym">{</span></span></li>
<li><a name="a1428"></a></span><span class="src-str">            <span class="src-key">if</span><span class="src-sym">(</span><span class="src-id">array_key_exists</span><span class="src-sym">(</span><span class="src-var">$association_name</span><span class="src-sym">,</span> <span class="src-var">$this</span></span><span class="src-sym">-&gt;</span><a href="../PHPonTrax/ActiveRecord.html#var$has_many">has_many</a><span class="src-sym">)) </span><span class="src-str"></span><span class="src-sym">{</span></span></li>
<li><a name="a1429"></a></span><span class="src-str">                <span class="src-var">$type</span> = <span class="src-str">&quot;has_many&quot;</span><span class="src-sym">;</span>     </span></li>
<li><a name="a1430"></a></span><span class="src-str">            <span class="src-sym">}</span></span></li>
<li><a name="a1431"></a></span><span class="src-str">        <span class="src-sym">}</span></span></li>
<li><a name="a1432"></a></span><span class="src-str">        <span class="src-key">if</span><span class="src-sym">(</span><span class="src-id">is_string</span><span class="src-sym">(</span><span class="src-var">$this</span></span><span class="src-sym">-&gt;</span><a href="../PHPonTrax/ActiveRecord.html#var$has_one">has_one</a><span class="src-sym">)) </span><span class="src-str"></span><span class="src-sym">{</span></span></li>
<li><a name="a1433"></a></span><span class="src-str">            <span class="src-key">if</span><span class="src-sym">(</span><span class="src-id">preg_match</span><span class="src-sym">(</span><span class="src-str">"</span>/<span class="src-var">$association_name</span>/<span class="src-str">"</span><span class="src-sym">,</span> <span class="src-var">$this</span></span><span class="src-sym">-&gt;</span><a href="../PHPonTrax/ActiveRecord.html#var$has_one">has_one</a><span class="src-sym">)) </span><span class="src-str"></span><span class="src-sym">{</span></span></li>
<li><a name="a1434"></a></span><span class="src-str">                <span class="src-var">$type</span> = <span class="src-str">&quot;has_one&quot;</span><span class="src-sym">;</span>     </span></li>
<li><a name="a1435"></a></span><span class="src-str">            <span class="src-sym">}</span></span></li>
<li><a name="a1436"></a></span><span class="src-str">        <span class="src-sym">}</span> <span class="src-key">elseif</span><span class="src-sym">(</span><span class="src-id">is_array</span><span class="src-sym">(</span><span class="src-var">$this</span></span><span class="src-sym">-&gt;</span><a href="../PHPonTrax/ActiveRecord.html#var$has_one">has_one</a><span class="src-sym">)) </span><span class="src-str"></span><span class="src-sym">{</span></span></li>
<li><a name="a1437"></a></span><span class="src-str">            <span class="src-key">if</span><span class="src-sym">(</span><span class="src-id">array_key_exists</span><span class="src-sym">(</span><span class="src-var">$association_name</span><span class="src-sym">,</span> <span class="src-var">$this</span></span><span class="src-sym">-&gt;</span><a href="../PHPonTrax/ActiveRecord.html#var$has_one">has_one</a><span class="src-sym">)) </span><span class="src-str"></span><span class="src-sym">{</span></span></li>
<li><a name="a1438"></a></span><span class="src-str">                <span class="src-var">$type</span> = <span class="src-str">&quot;has_one&quot;</span><span class="src-sym">;</span>     </span></li>
<li><a name="a1439"></a></span><span class="src-str">            <span class="src-sym">}</span></span></li>
<li><a name="a1440"></a></span><span class="src-str">        <span class="src-sym">}</span></span></li>
<li><a name="a1441"></a></span><span class="src-str">        <span class="src-key">if</span><span class="src-sym">(</span><span class="src-id">is_string</span><span class="src-sym">(</span><span class="src-var">$this</span></span><span class="src-sym">-&gt;</span><a href="../PHPonTrax/ActiveRecord.html#var$belongs_to">belongs_to</a><span class="src-sym">)) </span><span class="src-str"></span><span class="src-sym">{</span> </span></li>
<li><a name="a1442"></a></span><span class="src-str">            <span class="src-key">if</span><span class="src-sym">(</span><span class="src-id">preg_match</span><span class="src-sym">(</span><span class="src-str">"</span>/<span class="src-var">$association_name</span>/<span class="src-str">"</span><span class="src-sym">,</span> <span class="src-var">$this</span></span><span class="src-sym">-&gt;</span><a href="../PHPonTrax/ActiveRecord.html#var$belongs_to">belongs_to</a><span class="src-sym">)) </span><span class="src-str"></span><span class="src-sym">{</span></span></li>
<li><a name="a1443"></a></span><span class="src-str">                <span class="src-var">$type</span> = <span class="src-str">&quot;belongs_to&quot;</span><span class="src-sym">;</span>      </span></li>
<li><a name="a1444"></a></span><span class="src-str">            <span class="src-sym">}</span></span></li>
<li><a name="a1445"></a></span><span class="src-str">        <span class="src-sym">}</span> <span class="src-key">elseif</span><span class="src-sym">(</span><span class="src-id">is_array</span><span class="src-sym">(</span><span class="src-var">$this</span></span><span class="src-sym">-&gt;</span><a href="../PHPonTrax/ActiveRecord.html#var$belongs_to">belongs_to</a><span class="src-sym">)) </span><span class="src-str"></span><span class="src-sym">{</span></span></li>
<li><a name="a1446"></a></span><span class="src-str">            <span class="src-key">if</span><span class="src-sym">(</span><span class="src-id">array_key_exists</span><span class="src-sym">(</span><span class="src-var">$association_name</span><span class="src-sym">,</span> <span class="src-var">$this</span></span><span class="src-sym">-&gt;</span><a href="../PHPonTrax/ActiveRecord.html#var$belongs_to">belongs_to</a><span class="src-sym">)) </span><span class="src-str"></span><span class="src-sym">{</span></span></li>
<li><a name="a1447"></a></span><span class="src-str">                <span class="src-var">$type</span> = <span class="src-str">&quot;belongs_to&quot;</span><span class="src-sym">;</span>      </span></li>
<li><a name="a1448"></a></span><span class="src-str">            <span class="src-sym">}</span></span></li>
<li><a name="a1449"></a></span><span class="src-str">        <span class="src-sym">}</span></span></li>
<li><a name="a1450"></a></span><span class="src-str">        <span class="src-key">if</span><span class="src-sym">(</span><span class="src-id">is_string</span><span class="src-sym">(</span><span class="src-var">$this</span></span><span class="src-sym">-&gt;</span><a href="../PHPonTrax/ActiveRecord.html#var$has_and_belongs_to_many">has_and_belongs_to_many</a><span class="src-sym">)) </span><span class="src-str"></span><span class="src-sym">{</span></span></li>
<li><a name="a1451"></a></span><span class="src-str">            <span class="src-key">if</span><span class="src-sym">(</span><span class="src-id">preg_match</span><span class="src-sym">(</span><span class="src-str">"</span>/<span class="src-var">$association_name</span>/<span class="src-str">"</span><span class="src-sym">,</span> <span class="src-var">$this</span></span><span class="src-sym">-&gt;</span><a href="../PHPonTrax/ActiveRecord.html#var$has_and_belongs_to_many">has_and_belongs_to_many</a><span class="src-sym">)) </span><span class="src-str"></span><span class="src-sym">{</span></span></li>
<li><a name="a1452"></a></span><span class="src-str">                <span class="src-var">$type</span> = <span class="src-str">&quot;has_and_belongs_to_many&quot;</span><span class="src-sym">;</span>      </span></li>
<li><a name="a1453"></a></span><span class="src-str">            <span class="src-sym">}</span></span></li>
<li><a name="a1454"></a></span><span class="src-str">        <span class="src-sym">}</span> <span class="src-key">elseif</span><span class="src-sym">(</span><span class="src-id">is_array</span><span class="src-sym">(</span><span class="src-var">$this</span></span><span class="src-sym">-&gt;</span><a href="../PHPonTrax/ActiveRecord.html#var$has_and_belongs_to_many">has_and_belongs_to_many</a><span class="src-sym">)) </span><span class="src-str"></span><span class="src-sym">{</span></span></li>
<li><a name="a1455"></a></span><span class="src-str">            <span class="src-key">if</span><span class="src-sym">(</span><span class="src-id">array_key_exists</span><span class="src-sym">(</span><span class="src-var">$association_name</span><span class="src-sym">,</span> <span class="src-var">$this</span></span><span class="src-sym">-&gt;</span><a href="../PHPonTrax/ActiveRecord.html#var$has_and_belongs_to_many">has_and_belongs_to_many</a><span class="src-sym">)) </span><span class="src-str"></span><span class="src-sym">{</span></span></li>
<li><a name="a1456"></a></span><span class="src-str">                <span class="src-var">$type</span> = <span class="src-str">&quot;has_and_belongs_to_many&quot;</span><span class="src-sym">;</span>      </span></li>
<li><a name="a1457"></a></span><span class="src-str">            <span class="src-sym">}</span></span></li>
<li><a name="a1458"></a></span><span class="src-str">        <span class="src-sym">}</span>   </span></li>
<li><a name="a1459"></a></span><span class="src-str">        <span class="src-key">return</span> <span class="src-var">$type</span><span class="src-sym">;</span>   </span></li>
<li><a name="a1460"></a></span><span class="src-str">    <span class="src-sym">}</span></span></li>
<li><a name="a1461"></a></span><span class="src-str">    </span></li>
<li><a name="a1462"></a></span><span class="src-str">    /**</span></li>
<li><a name="a1463"></a></span><span class="src-str">     *  Saves any associations objects assigned to this instance</span></li>
<li><a name="a1464"></a></span><span class="src-str">     *  @uses $auto_save_associations</span></li>
<li><a name="a1465"></a></span><span class="src-str">     *  @todo Document this API</span></li>
<li><a name="a1466"></a></span><span class="src-str">     */</span></li>
<li><a name="a1467"></a></span><span class="src-str">    <span class="src-key">private</span> <span class="src-key">function</span> <span class="src-id">save_associations</span><span class="src-sym">(</span><span class="src-sym">)</span> <span class="src-sym">{</span>      </span></li>
<li><a name="a1468"></a></span><span class="src-str">        <span class="src-key">if</span><span class="src-sym">(</span><span class="src-id">count</span><span class="src-sym">(</span><span class="src-var">$this</span></span><span class="src-sym">-&gt;</span><a href="../PHPonTrax/ActiveRecord.html#var$save_associations">save_associations</a><span class="src-sym">) </span>&amp;&amp; <span class="src-var">$this</span><span class="src-sym">-&gt;</span><a href="../PHPonTrax/ActiveRecord.html#var$auto_save_associations">auto_save_associations</a><span class="src-sym">) </span><span class="src-str"></span><span class="src-sym">{</span></span></li>
<li><a name="a1469"></a></span><span class="src-str">            <span class="src-key">foreach</span><span class="src-sym">(</span><span class="src-id">array_keys</span><span class="src-sym">(</span><span class="src-var">$this</span></span><span class="src-sym">-&gt;</span><a href="../PHPonTrax/ActiveRecord.html#var$save_associations">save_associations</a><span class="src-sym">) </span><span class="src-key">as </span><span class="src-var">$type</span><span class="src-sym">) </span><span class="src-str"></span><span class="src-sym">{</span></span></li>
<li><a name="a1470"></a></span><span class="src-str">                <span class="src-key">if</span><span class="src-sym">(</span><span class="src-id">count</span><span class="src-sym">(</span><span class="src-var">$this</span></span><span class="src-sym">-&gt;</span><a href="../PHPonTrax/ActiveRecord.html#var$save_associations">save_associations</a><span class="src-sym">[</span><span class="src-var">$type</span><span class="src-sym">]</span><span class="src-sym">)) </span><span class="src-str"></span><span class="src-sym">{</span></span></li>
<li><a name="a1471"></a></span><span class="src-str">                    <span class="src-key">foreach</span><span class="src-sym">(</span><span class="src-var">$this</span></span><span class="src-sym">-&gt;</span><a href="../PHPonTrax/ActiveRecord.html#var$save_associations">save_associations</a><span class="src-sym">[</span><span class="src-var">$type</span><span class="src-sym">] </span><span class="src-key">as </span><span class="src-var">$object_or_array</span><span class="src-sym">) </span><span class="src-str"></span><span class="src-sym">{</span></span></li>
<li><a name="a1472"></a></span><span class="src-str">                        <span class="src-key">if</span><span class="src-sym">(</span><span class="src-id">is_object</span><span class="src-sym">(</span><span class="src-var">$object_or_array</span><span class="src-sym">))</span> <span class="src-sym">{</span></span></li>
<li><a name="a1473"></a></span><span class="src-str">                            <span class="src-var">$this</span></span><span class="src-sym">-&gt;</span><a href="../PHPonTrax/ActiveRecord.html#methodsave_association">save_association</a><span class="src-sym">(</span><span class="src-var">$object_or_array</span><span class="src-sym">, </span><span class="src-var">$type</span><span class="src-sym">)</span><span class="src-sym">;     </span></li>
<li><a name="a1474"></a>                        </span><span class="src-str"><span class="src-sym">}</span> <span class="src-key">elseif</span><span class="src-sym">(</span><span class="src-id">is_array</span><span class="src-sym">(</span><span class="src-var">$object_or_array</span><span class="src-sym">))</span> <span class="src-sym">{</span></span></li>
<li><a name="a1475"></a></span><span class="src-str">                            <span class="src-key">foreach</span><span class="src-sym">(</span><span class="src-var">$object_or_array</span> <span class="src-key">as</span> <span class="src-var">$object</span><span class="src-sym">)</span> <span class="src-sym">{</span></span></li>
<li><a name="a1476"></a></span><span class="src-str">                                <span class="src-var">$this</span></span><span class="src-sym">-&gt;</span><a href="../PHPonTrax/ActiveRecord.html#methodsave_association">save_association</a><span class="src-sym">(</span><span class="src-var">$object</span><span class="src-sym">, </span><span class="src-var">$type</span><span class="src-sym">)</span><span class="src-sym">;    </span></li>
<li><a name="a1477"></a>                            </span><span class="src-str"><span class="src-sym">}</span>    </span></li>
<li><a name="a1478"></a></span><span class="src-str">                        <span class="src-sym">}</span></span></li>
<li><a name="a1479"></a></span><span class="src-str">                    <span class="src-sym">}</span></span></li>
<li><a name="a1480"></a></span><span class="src-str">                <span class="src-sym">}</span></span></li>
<li><a name="a1481"></a></span><span class="src-str">            <span class="src-sym">}</span>    </span></li>
<li><a name="a1482"></a></span><span class="src-str">        <span class="src-sym">}</span>       </span></li>
<li><a name="a1483"></a></span><span class="src-str">    <span class="src-sym">}</span></span></li>
<li><a name="a1484"></a></span><span class="src-str">    </span></li>
<li><a name="a1485"></a></span><span class="src-str">    /**</span></li>
<li><a name="a1486"></a></span><span class="src-str">     *  save the association to the database</span></li>
<li><a name="a1487"></a></span><span class="src-str">     *  @todo Document this API</span></li>
<li><a name="a1488"></a></span><span class="src-str">     */</span></li>
<li><a name="a1489"></a></span><span class="src-str">    <span class="src-key">private</span> <span class="src-key">function</span> <span class="src-id">save_association</span><span class="src-sym">(</span><span class="src-var">$object</span><span class="src-sym">,</span> <span class="src-var">$type</span><span class="src-sym">)</span> <span class="src-sym">{</span></span></li>
<li><a name="a1490"></a></span><span class="src-str">        <span class="src-key">if</span><span class="src-sym">(</span><span class="src-id">is_object</span><span class="src-sym">(</span><span class="src-var">$object</span><span class="src-sym">)</span> &amp;&amp; <span class="src-id">get_parent_class</span><span class="src-sym">(</span><span class="src-var">$object</span><span class="src-sym">)</span> == __CLASS__ &amp;&amp; <span class="src-var">$type</span><span class="src-sym">)</span> <span class="src-sym">{</span></span></li>
<li><a name="a1491"></a></span><span class="src-str">            <span class="src-comm">//echo get_class($object).&quot; - type:$type&lt;br&gt;&quot;;</span></span></li>
<li><a name="a1492"></a></span><span class="src-str"><span class="src-comm"></span>            <span class="src-key">switch</span><span class="src-sym">(</span><span class="src-var">$type</span><span class="src-sym">)</span> <span class="src-sym">{</span></span></li>
<li><a name="a1493"></a></span><span class="src-str">                <span class="src-key">case</span> <span class="src-str">&quot;has_many&quot;</span>:</span></li>
<li><a name="a1494"></a></span><span class="src-str">                <span class="src-key">case</span> <span class="src-str">&quot;has_one&quot;</span>:</span></li>
<li><a name="a1495"></a></span><span class="src-str">                    <span class="src-var">$foreign_key</span> = <span class="src-id">Inflector</span><span class="src-sym">::</span><span class="src-id">singularize</span><span class="src-sym">(</span><span class="src-var">$this</span></span><span class="src-sym">-&gt;</span><a href="../PHPonTrax/ActiveRecord.html#var$table_name">table_name</a><span class="src-sym">)</span>.<span class="src-str">&quot;_id&quot;</span><span class="src-sym">;</span></li>
<li><a name="a1496"></a>                    <span class="src-var">$object</span><span class="src-sym">-&gt;</span><span class="src-var">$foreign_key </span>= <span class="src-var">$this</span><span class="src-sym">-&gt;</span><span class="src-var">id</span><span class="src-sym">; </span></li>
<li><a name="a1497"></a>                    <span class="src-comm">//echo &quot;fk:$foreign_key = $this-&gt;id&lt;br&gt;&quot;;</span></li>
<li><a name="a1498"></a>                    <span class="src-key">break</span><span class="src-sym">;</span></li>
<li><a name="a1499"></a>            </span><span class="src-str"><span class="src-sym">}</span></span></li>
<li><a name="a1500"></a></span><span class="src-str">            <span class="src-var">$object</span></span><span class="src-sym">-&gt;</span><span class="src-id">save</span><span class="src-sym">(</span><span class="src-sym">)</span><span class="src-sym">;        </span></li>
<li><a name="a1501"></a>        </span><span class="src-str"><span class="src-sym">}</span>            </span></li>
<li><a name="a1502"></a></span><span class="src-str">    <span class="src-sym">}</span></span></li>
<li><a name="a1503"></a>&nbsp;</li>
<li><a name="a1504"></a></span><span class="src-str">    /**</span></li>
<li><a name="a1505"></a></span><span class="src-str">     *  Deletes the record with the given $id or if you have done a</span></li>
<li><a name="a1506"></a></span><span class="src-str">     *  $model = $model-&gt;find($id), then $model-&gt;delete() it will delete</span></li>
<li><a name="a1507"></a></span><span class="src-str">     *  the record it just loaded from the find() without passing anything</span></li>
<li><a name="a1508"></a></span><span class="src-str">     *  to delete(). If an array of ids is provided, all ids in array are deleted.</span></li>
<li><a name="a1509"></a></span><span class="src-str">     *  @uses $errors</span></li>
<li><a name="a1510"></a></span><span class="src-str">     *  @todo Document this API</span></li>
<li><a name="a1511"></a></span><span class="src-str">     */</span></li>
<li><a name="a1512"></a></span><span class="src-str">    <span class="src-key">function</span> <span class="src-id">delete</span><span class="src-sym">(</span><span class="src-var">$id</span> = <span class="src-id">null</span><span class="src-sym">)</span> <span class="src-sym">{</span></span></li>
<li><a name="a1513"></a></span><span class="src-str">        <span class="src-key">if</span><span class="src-sym">(</span><span class="src-var">$this</span></span><span class="src-sym">-&gt;</span><span class="src-var">id </span>&gt; <span class="src-num">0 </span>&amp;&amp; <span class="src-id">is_null</span><span class="src-sym">(</span><span class="src-var">$id</span><span class="src-sym">)) </span><span class="src-str"></span><span class="src-sym">{</span></span></li>
<li><a name="a1514"></a></span><span class="src-str">            <span class="src-var">$id</span> = <span class="src-var">$this</span></span><span class="src-sym">-&gt;</span><span class="src-var">id</span><span class="src-sym">;</span></li>
<li><a name="a1515"></a>        </span><span class="src-str"><span class="src-sym">}</span></span></li>
<li><a name="a1516"></a>&nbsp;</li>
<li><a name="a1517"></a></span><span class="src-str">        <span class="src-key">if</span><span class="src-sym">(</span><span class="src-id">is_null</span><span class="src-sym">(</span><span class="src-var">$id</span><span class="src-sym">))</span> <span class="src-sym">{</span></span></li>
<li><a name="a1518"></a></span><span class="src-str">            <span class="src-var">$this</span></span><span class="src-sym">-&gt;</span><a href="../PHPonTrax/ActiveRecord.html#var$errors">errors</a><span class="src-sym">[</span><span class="src-sym">] </span>= <span class="src-str">&quot;No id specified to delete on.&quot;</span><span class="src-sym">;</span></li>
<li><a name="a1519"></a>            <span class="src-key">return </span><span class="src-id">false</span><span class="src-sym">;</span></li>
<li><a name="a1520"></a>        </span><span class="src-str"><span class="src-sym">}</span></span></li>
<li><a name="a1521"></a>&nbsp;</li>
<li><a name="a1522"></a></span><span class="src-str">        <span class="src-var">$this</span></span><span class="src-sym">-&gt;</span><a href="../PHPonTrax/ActiveRecord.html#methodbefore_delete">before_delete</a><span class="src-sym">(</span><span class="src-sym">)</span><span class="src-sym">;</span></li>
<li><a name="a1523"></a>        <span class="src-var">$result </span>= <span class="src-var">$this</span><span class="src-sym">-&gt;</span><a href="../PHPonTrax/ActiveRecord.html#methoddelete_all">delete_all</a><span class="src-sym">(</span><span class="src-str"></span><span class="src-str">"</span><span class="src-id">id</span> <span class="src-id">IN</span> (<span class="src-var">$id</span>)<span class="src-str">"</span><span class="src-sym">)</span><span class="src-sym">;</span></span></li>
<li><a name="a1524"></a></span><span class="src-str">        <span class="src-key">if</span><span class="src-sym">(</span><span class="src-var">$this</span></span><span class="src-sym">-&gt;</span><a href="../PHPonTrax/ActiveRecord.html#var$auto_delete_habtm">auto_delete_habtm</a><span class="src-sym">) </span><span class="src-str"></span><span class="src-sym">{</span></span></li>
<li><a name="a1525"></a></span><span class="src-str">            <span class="src-key">if</span><span class="src-sym">(</span><span class="src-id">is_string</span><span class="src-sym">(</span><span class="src-var">$this</span></span><span class="src-sym">-&gt;</span><a href="../PHPonTrax/ActiveRecord.html#var$has_and_belongs_to_many">has_and_belongs_to_many</a><span class="src-sym">)) </span><span class="src-str"></span><span class="src-sym">{</span></span></li>
<li><a name="a1526"></a></span><span class="src-str">                <span class="src-var">$habtms</span> = <span class="src-id">explode</span><span class="src-sym">(</span><span class="src-str">&quot;,&quot;</span><span class="src-sym">,</span> <span class="src-var">$this</span></span><span class="src-sym">-&gt;</span><a href="../PHPonTrax/ActiveRecord.html#var$has_and_belongs_to_many">has_and_belongs_to_many</a><span class="src-sym">)</span><span class="src-sym">;</span></li>
<li><a name="a1527"></a>                <span class="src-key">foreach</span><span class="src-sym">(</span><span class="src-var">$habtms </span><span class="src-key">as </span><span class="src-var">$other_table_name</span><span class="src-sym">) </span><span class="src-str"></span><span class="src-sym">{</span></span></li>
<li><a name="a1528"></a></span><span class="src-str">                    <span class="src-var">$this</span></span><span class="src-sym">-&gt;</span><a href="../PHPonTrax/ActiveRecord.html#methoddelete_all_habtm_records">delete_all_habtm_records</a><span class="src-sym">(</span><span class="src-id">trim</span><span class="src-sym">(</span><span class="src-var">$other_table_name</span><span class="src-sym">)</span><span class="src-sym">, </span><span class="src-var">$id</span><span class="src-sym">)</span><span class="src-sym">;                             </span></li>
<li><a name="a1529"></a>                </span><span class="src-str"><span class="src-sym">}</span></span></li>
<li><a name="a1530"></a></span><span class="src-str">            <span class="src-sym">}</span> <span class="src-key">elseif</span><span class="src-sym">(</span><span class="src-id">is_array</span><span class="src-sym">(</span><span class="src-var">$this</span></span><span class="src-sym">-&gt;</span><a href="../PHPonTrax/ActiveRecord.html#var$has_and_belongs_to_many">has_and_belongs_to_many</a><span class="src-sym">)) </span><span class="src-str"></span><span class="src-sym">{</span></span></li>
<li><a name="a1531"></a></span><span class="src-str">                <span class="src-key">foreach</span><span class="src-sym">(</span><span class="src-var">$this</span></span><span class="src-sym">-&gt;</span><a href="../PHPonTrax/ActiveRecord.html#var$has_and_belongs_to_many">has_and_belongs_to_many</a> <span class="src-key">as </span><span class="src-var">$other_table_name </span>=&gt; <span class="src-var">$values</span><span class="src-sym">) </span><span class="src-str"></span><span class="src-sym">{</span></span></li>
<li><a name="a1532"></a></span><span class="src-str">                    <span class="src-var">$this</span></span><span class="src-sym">-&gt;</span><a href="../PHPonTrax/ActiveRecord.html#methoddelete_all_habtm_records">delete_all_habtm_records</a><span class="src-sym">(</span><span class="src-var">$other_table_name</span><span class="src-sym">, </span><span class="src-var">$id</span><span class="src-sym">)</span><span class="src-sym">;                             </span></li>
<li><a name="a1533"></a>                </span><span class="src-str"><span class="src-sym">}</span></span></li>
<li><a name="a1534"></a></span><span class="src-str">            <span class="src-sym">}</span> </span></li>
<li><a name="a1535"></a></span><span class="src-str">        <span class="src-sym">}</span></span></li>
<li><a name="a1536"></a></span><span class="src-str">        <span class="src-var">$this</span></span><span class="src-sym">-&gt;</span><a href="../PHPonTrax/ActiveRecord.html#methodafter_delete">after_delete</a><span class="src-sym">(</span><span class="src-sym">)</span><span class="src-sym">;</span></li>
<li><a name="a1537"></a>&nbsp;</li>
<li><a name="a1538"></a>        <span class="src-key">return </span><span class="src-var">$result</span><span class="src-sym">;</span></li>
<li><a name="a1539"></a>    </span><span class="src-str"><span class="src-sym">}</span></span></li>
<li><a name="a1540"></a>&nbsp;</li>
<li><a name="a1541"></a></span><span class="src-str">    /**</span></li>
<li><a name="a1542"></a></span><span class="src-str">     *  Delete from table all rows that match argument</span></li>
<li><a name="a1543"></a></span><span class="src-str">     *</span></li>
<li><a name="a1544"></a></span><span class="src-str">     *  Delete the row(s), if any, matching the argument.</span></li>
<li><a name="a1545"></a></span><span class="src-str">     *  @param string $conditions SQL argument to &quot;WHERE&quot; describing</span></li>
<li><a name="a1546"></a></span><span class="src-str">     *                the rows to delete</span></li>
<li><a name="a1547"></a></span><span class="src-str">     *  @return boolean</span></li>
<li><a name="a1548"></a></span><span class="src-str">     *          &lt;ul&gt;</span></li>
<li><a name="a1549"></a></span><span class="src-str">     *            &lt;li&gt;true =&gt; One or more rows were deleted&lt;/li&gt;</span></li>
<li><a name="a1550"></a></span><span class="src-str">     *            &lt;li&gt;false =&gt; $conditions was omitted&lt;/li&gt;</span></li>
<li><a name="a1551"></a></span><span class="src-str">     *          &lt;/ul&gt;</span></li>
<li><a name="a1552"></a></span><span class="src-str">     *  @uses is_error()</span></li>
<li><a name="a1553"></a></span><span class="src-str">     *  @uses $new_record</span></li>
<li><a name="a1554"></a></span><span class="src-str">     *  @uses $errors</span></li>
<li><a name="a1555"></a></span><span class="src-str">     *  @uses query()</span></li>
<li><a name="a1556"></a></span><span class="src-str">     *  @throws {@link ActiveRecordError}</span></li>
<li><a name="a1557"></a></span><span class="src-str">     */</span></li>
<li><a name="a1558"></a></span><span class="src-str">    <span class="src-key">function</span> <span class="src-id">delete_all</span><span class="src-sym">(</span><span class="src-var">$conditions</span> = <span class="src-id">null</span><span class="src-sym">)</span> <span class="src-sym">{</span></span></li>
<li><a name="a1559"></a></span><span class="src-str">        <span class="src-key">if</span><span class="src-sym">(</span><span class="src-id">is_null</span><span class="src-sym">(</span><span class="src-var">$conditions</span><span class="src-sym">))</span> <span class="src-sym">{</span></span></li>
<li><a name="a1560"></a></span><span class="src-str">            <span class="src-var">$this</span></span><span class="src-sym">-&gt;</span><a href="../PHPonTrax/ActiveRecord.html#var$errors">errors</a><span class="src-sym">[</span><span class="src-sym">] </span>= <span class="src-str">&quot;No conditions specified to delete on.&quot;</span><span class="src-sym">;</span></li>
<li><a name="a1561"></a>            <span class="src-key">return </span><span class="src-id">false</span><span class="src-sym">;</span></li>
<li><a name="a1562"></a>        </span><span class="src-str"><span class="src-sym">}</span></span></li>
<li><a name="a1563"></a>&nbsp;</li>
<li><a name="a1564"></a></span><span class="src-str">        <span class="src-comm"># Delete the record(s)</span></span></li>
<li><a name="a1565"></a></span><span class="src-str"><span class="src-comm"></span>        <span class="src-key">if</span><span class="src-sym">(</span><span class="src-var">$this</span></span><span class="src-sym">-&gt;</span><a href="../PHPonTrax/ActiveRecord.html#methodis_error">is_error</a><span class="src-sym">(</span><span class="src-var">$rs </span>= <span class="src-var">$this</span><span class="src-sym">-&gt;</span><a href="../PHPonTrax/ActiveRecord.html#methodquery">query</a><span class="src-sym">(</span><span class="src-str"></span><span class="src-str">"</span><span class="src-id">DELETE</span> <span class="src-id">FROM</span> <span class="src-var">$this</span></span><span class="src-sym">-&gt;</span><a href="../PHPonTrax/ActiveRecord.html#var$table_name">table_name</a> <span class="src-id">WHERE </span><span class="src-var">$conditions</span><span class="src-str"></span><span class="src-str">"</span><span class="src-sym">)))</span> <span class="src-sym">{</span></span></li>
<li><a name="a1566"></a></span><span class="src-str">            <span class="src-var">$this</span></span><span class="src-sym">-&gt;</span><a href="../PHPonTrax/ActiveRecord.html#methodraise">raise</a><span class="src-sym">(</span><span class="src-var">$rs</span><span class="src-sym">-&gt;</span><span class="src-id">getMessage</span><span class="src-sym">(</span><span class="src-sym">))</span><span class="src-sym">;</span></li>
<li><a name="a1567"></a>        </span><span class="src-str"><span class="src-sym">}</span></span></li>
<li><a name="a1568"></a>&nbsp;</li>
<li><a name="a1569"></a></span><span class="src-str">        <span class="src-comm">//  &lt;b&gt;FIXME: We don't know whether this row was deleted.</span></span></li>
<li><a name="a1570"></a></span><span class="src-str"><span class="src-comm"></span>        <span class="src-comm">//    What are the implications of making this a new record?&lt;/b&gt;</span></span></li>
<li><a name="a1571"></a></span><span class="src-str"><span class="src-comm"></span>        <span class="src-var">$this</span></span><span class="src-sym">-&gt;</span><span class="src-var">id </span>= <span class="src-num">0</span><span class="src-sym">;</span></li>
<li><a name="a1572"></a>        <span class="src-var">$this</span><span class="src-sym">-&gt;</span><a href="../PHPonTrax/ActiveRecord.html#var$new_record">new_record</a> = <span class="src-id">true</span><span class="src-sym">;</span></li>
<li><a name="a1573"></a>        <span class="src-key">return </span><span class="src-id">true</span><span class="src-sym">;</span></li>
<li><a name="a1574"></a>    </span><span class="src-str"><span class="src-sym">}</span></span></li>
<li><a name="a1575"></a>&nbsp;</li>
<li><a name="a1576"></a></span><span class="src-str">    /**</span></li>
<li><a name="a1577"></a></span><span class="src-str">     *  @uses $has_and_belongs_to_many</span></li>
<li><a name="a1578"></a></span><span class="src-str">     *  @todo Document this API</span></li>
<li><a name="a1579"></a></span><span class="src-str">     */</span></li>
<li><a name="a1580"></a></span><span class="src-str">    <span class="src-key">private</span> <span class="src-key">function</span> <span class="src-id">set_habtm_attributes</span><span class="src-sym">(</span><span class="src-var">$attributes</span><span class="src-sym">)</span> <span class="src-sym">{</span></span></li>
<li><a name="a1581"></a></span><span class="src-str">        <span class="src-key">if</span><span class="src-sym">(</span><span class="src-id">is_array</span><span class="src-sym">(</span><span class="src-var">$attributes</span><span class="src-sym">))</span> <span class="src-sym">{</span></span></li>
<li><a name="a1582"></a></span><span class="src-str">            <span class="src-var">$this</span></span><span class="src-sym">-&gt;</span><a href="../PHPonTrax/ActiveRecord.html#var$habtm_attributes">habtm_attributes</a> = <span class="src-key">array</span><span class="src-sym">(</span><span class="src-sym">)</span><span class="src-sym">;</span></li>
<li><a name="a1583"></a>            <span class="src-key">foreach</span><span class="src-sym">(</span><span class="src-var">$attributes </span><span class="src-key">as </span><span class="src-var">$key </span>=&gt; <span class="src-var">$habtm_array</span><span class="src-sym">) </span><span class="src-str"></span><span class="src-sym">{</span></span></li>
<li><a name="a1584"></a></span><span class="src-str">                <span class="src-key">if</span><span class="src-sym">(</span><span class="src-id">is_array</span><span class="src-sym">(</span><span class="src-var">$habtm_array</span><span class="src-sym">))</span> <span class="src-sym">{</span></span></li>
<li><a name="a1585"></a></span><span class="src-str">                    <span class="src-key">if</span><span class="src-sym">(</span><span class="src-id">is_string</span><span class="src-sym">(</span><span class="src-var">$this</span></span><span class="src-sym">-&gt;</span><a href="../PHPonTrax/ActiveRecord.html#var$has_and_belongs_to_many">has_and_belongs_to_many</a><span class="src-sym">)) </span><span class="src-str"></span><span class="src-sym">{</span></span></li>
<li><a name="a1586"></a></span><span class="src-str">                        <span class="src-key">if</span><span class="src-sym">(</span><span class="src-id">preg_match</span><span class="src-sym">(</span><span class="src-str">"</span>/<span class="src-var">$key</span>/<span class="src-str">"</span><span class="src-sym">,</span> <span class="src-var">$this</span></span><span class="src-sym">-&gt;</span><a href="../PHPonTrax/ActiveRecord.html#var$has_and_belongs_to_many">has_and_belongs_to_many</a><span class="src-sym">)) </span><span class="src-str"></span><span class="src-sym">{</span></span></li>
<li><a name="a1587"></a></span><span class="src-str">                            <span class="src-var">$this</span></span><span class="src-sym">-&gt;</span><a href="../PHPonTrax/ActiveRecord.html#var$habtm_attributes">habtm_attributes</a><span class="src-sym">[</span><span class="src-var">$key</span><span class="src-sym">] </span>= <span class="src-var">$habtm_array</span><span class="src-sym">;</span></li>
<li><a name="a1588"></a>                        </span><span class="src-str"><span class="src-sym">}</span></span></li>
<li><a name="a1589"></a></span><span class="src-str">                    <span class="src-sym">}</span> <span class="src-key">elseif</span><span class="src-sym">(</span><span class="src-id">is_array</span><span class="src-sym">(</span><span class="src-var">$this</span></span><span class="src-sym">-&gt;</span><a href="../PHPonTrax/ActiveRecord.html#var$has_and_belongs_to_many">has_and_belongs_to_many</a><span class="src-sym">)) </span><span class="src-str"></span><span class="src-sym">{</span></span></li>
<li><a name="a1590"></a></span><span class="src-str">                        <span class="src-key">if</span><span class="src-sym">(</span><span class="src-id">array_key_exists</span><span class="src-sym">(</span><span class="src-var">$key</span><span class="src-sym">,</span> <span class="src-var">$this</span></span><span class="src-sym">-&gt;</span><a href="../PHPonTrax/ActiveRecord.html#var$has_and_belongs_to_many">has_and_belongs_to_many</a><span class="src-sym">)) </span><span class="src-str"></span><span class="src-sym">{</span></span></li>
<li><a name="a1591"></a></span><span class="src-str">                            <span class="src-var">$this</span></span><span class="src-sym">-&gt;</span><a href="../PHPonTrax/ActiveRecord.html#var$habtm_attributes">habtm_attributes</a><span class="src-sym">[</span><span class="src-var">$key</span><span class="src-sym">] </span>= <span class="src-var">$habtm_array</span><span class="src-sym">;</span></li>
<li><a name="a1592"></a>                        </span><span class="src-str"><span class="src-sym">}</span></span></li>
<li><a name="a1593"></a></span><span class="src-str">                    <span class="src-sym">}</span></span></li>
<li><a name="a1594"></a></span><span class="src-str">                <span class="src-sym">}</span></span></li>
<li><a name="a1595"></a></span><span class="src-str">            <span class="src-sym">}</span></span></li>
<li><a name="a1596"></a></span><span class="src-str">        <span class="src-sym">}</span></span></li>
<li><a name="a1597"></a></span><span class="src-str">    <span class="src-sym">}</span></span></li>
<li><a name="a1598"></a>&nbsp;</li>
<li><a name="a1599"></a></span><span class="src-str">    /**</span></li>
<li><a name="a1600"></a></span><span class="src-str">     *</span></li>
<li><a name="a1601"></a></span><span class="src-str">     *  @todo Document this API</span></li>
<li><a name="a1602"></a></span><span class="src-str">     */</span></li>
<li><a name="a1603"></a></span><span class="src-str">    <span class="src-key">private</span> <span class="src-key">function</span> <span class="src-id">update_habtm_records</span><span class="src-sym">(</span><span class="src-var">$this_foreign_value</span><span class="src-sym">)</span> <span class="src-sym">{</span></span></li>
<li><a name="a1604"></a></span><span class="src-str">        <span class="src-key">return</span> <span class="src-var">$this</span></span><span class="src-sym">-&gt;</span><a href="../PHPonTrax/ActiveRecord.html#methodadd_habtm_records">add_habtm_records</a><span class="src-sym">(</span><span class="src-var">$this_foreign_value</span><span class="src-sym">)</span><span class="src-sym">;</span></li>
<li><a name="a1605"></a>    </span><span class="src-str"><span class="src-sym">}</span></span></li>
<li><a name="a1606"></a>&nbsp;</li>
<li><a name="a1607"></a></span><span class="src-str">    /**</span></li>
<li><a name="a1608"></a></span><span class="src-str">     *</span></li>
<li><a name="a1609"></a></span><span class="src-str">     *  @uses is_error()</span></li>
<li><a name="a1610"></a></span><span class="src-str">     *  @uses query()</span></li>
<li><a name="a1611"></a></span><span class="src-str">     *  @throws {@link ActiveRecordError}</span></li>
<li><a name="a1612"></a></span><span class="src-str">     *  @todo Document this API</span></li>
<li><a name="a1613"></a></span><span class="src-str">     */</span></li>
<li><a name="a1614"></a></span><span class="src-str">    <span class="src-key">private</span> <span class="src-key">function</span> <span class="src-id">add_habtm_records</span><span class="src-sym">(</span><span class="src-var">$this_foreign_value</span><span class="src-sym">)</span> <span class="src-sym">{</span></span></li>
<li><a name="a1615"></a></span><span class="src-str">        <span class="src-key">if</span><span class="src-sym">(</span><span class="src-var">$this_foreign_value</span> > <span class="src-num">0</span> &amp;&amp; <span class="src-id">count</span><span class="src-sym">(</span><span class="src-var">$this</span></span><span class="src-sym">-&gt;</span><a href="../PHPonTrax/ActiveRecord.html#var$habtm_attributes">habtm_attributes</a><span class="src-sym">) </span>&gt; <span class="src-num">0</span><span class="src-sym">) </span><span class="src-str"></span><span class="src-sym">{</span></span></li>
<li><a name="a1616"></a></span><span class="src-str">            <span class="src-key">if</span><span class="src-sym">(</span><span class="src-var">$this</span></span><span class="src-sym">-&gt;</span><a href="../PHPonTrax/ActiveRecord.html#methoddelete_habtm_records">delete_habtm_records</a><span class="src-sym">(</span><span class="src-var">$this_foreign_value</span><span class="src-sym">)) </span><span class="src-str"></span><span class="src-sym">{</span></span></li>
<li><a name="a1617"></a></span><span class="src-str">                <span class="src-id">reset</span><span class="src-sym">(</span><span class="src-var">$this</span></span><span class="src-sym">-&gt;</span><a href="../PHPonTrax/ActiveRecord.html#var$habtm_attributes">habtm_attributes</a><span class="src-sym">)</span><span class="src-sym">;</span></li>
<li><a name="a1618"></a>                <span class="src-key">foreach</span><span class="src-sym">(</span><span class="src-var">$this</span><span class="src-sym">-&gt;</span><a href="../PHPonTrax/ActiveRecord.html#var$habtm_attributes">habtm_attributes</a> <span class="src-key">as </span><span class="src-var">$other_table_name </span>=&gt; <span class="src-var">$other_foreign_values</span><span class="src-sym">) </span><span class="src-str"></span><span class="src-sym">{</span></span></li>
<li><a name="a1619"></a></span><span class="src-str">                    <span class="src-var">$table_name</span> = <span class="src-var">$this</span></span><span class="src-sym">-&gt;</span><a href="../PHPonTrax/ActiveRecord.html#methodget_join_table_name">get_join_table_name</a><span class="src-sym">(</span><span class="src-var">$this</span><span class="src-sym">-&gt;</span><a href="../PHPonTrax/ActiveRecord.html#var$table_name">table_name</a><span class="src-sym">,</span><span class="src-var">$other_table_name</span><span class="src-sym">)</span><span class="src-sym">;</span></li>
<li><a name="a1620"></a>                    <span class="src-var">$other_foreign_key </span>= <span class="src-id">Inflector</span><span class="src-sym">::</span><span class="src-id">singularize</span><span class="src-sym">(</span><span class="src-var">$other_table_name</span><span class="src-sym">)</span>.<span class="src-str">&quot;_id&quot;</span><span class="src-sym">;</span></li>
<li><a name="a1621"></a>                    <span class="src-var">$this_foreign_key </span>= <span class="src-id">Inflector</span><span class="src-sym">::</span><span class="src-id">singularize</span><span class="src-sym">(</span><span class="src-var">$this</span><span class="src-sym">-&gt;</span><a href="../PHPonTrax/ActiveRecord.html#var$table_name">table_name</a><span class="src-sym">)</span>.<span class="src-str">&quot;_id&quot;</span><span class="src-sym">;</span></li>
<li><a name="a1622"></a>                    <span class="src-key">foreach</span><span class="src-sym">(</span><span class="src-var">$other_foreign_values </span><span class="src-key">as </span><span class="src-var">$other_foreign_value</span><span class="src-sym">) </span><span class="src-str"></span><span class="src-sym">{</span></span></li>
<li><a name="a1623"></a></span><span class="src-str">                        unset<span class="src-sym">(</span><span class="src-var">$attributes</span><span class="src-sym">)</span><span class="src-sym">;</span></span></li>
<li><a name="a1624"></a></span><span class="src-str">                        <span class="src-var">$attributes</span><span class="src-sym">[</span><span class="src-var">$this_foreign_key</span><span class="src-sym">]</span> = <span class="src-var">$this_foreign_value</span><span class="src-sym">;</span></span></li>
<li><a name="a1625"></a></span><span class="src-str">                        <span class="src-var">$attributes</span><span class="src-sym">[</span><span class="src-var">$other_foreign_key</span><span class="src-sym">]</span> = <span class="src-var">$other_foreign_value</span><span class="src-sym">;</span></span></li>
<li><a name="a1626"></a></span><span class="src-str">                        <span class="src-var">$attributes</span> = <span class="src-var">$this</span></span><span class="src-sym">-&gt;</span><a href="../PHPonTrax/ActiveRecord.html#methodquoted_attributes">quoted_attributes</a><span class="src-sym">(</span><span class="src-var">$attributes</span><span class="src-sym">)</span><span class="src-sym">;</span></li>
<li><a name="a1627"></a>                        <span class="src-var">$fields </span>= <span class="src-sym">@</span><span class="src-id">implode</span><span class="src-sym">(</span><span class="src-str">', '</span><span class="src-sym">, </span><span class="src-id">array_keys</span><span class="src-sym">(</span><span class="src-var">$attributes</span><span class="src-sym">))</span><span class="src-sym">;</span></li>
<li><a name="a1628"></a>                        <span class="src-var">$values </span>= <span class="src-sym">@</span><span class="src-id">implode</span><span class="src-sym">(</span><span class="src-str">', '</span><span class="src-sym">, </span><span class="src-id">array_values</span><span class="src-sym">(</span><span class="src-var">$attributes</span><span class="src-sym">))</span><span class="src-sym">;</span></li>
<li><a name="a1629"></a>                        <span class="src-var">$sql </span>= </span><span class="src-str"><span class="src-str">"</span><span class="src-id">INSERT</span> <span class="src-id">INTO</span> <span class="src-var">$table_name</span> (<span class="src-var">$fields</span>) <span class="src-id">VALUES</span> (<span class="src-var">$values</span>)<span class="src-str">"</span><span class="src-sym">;</span></span></li>
<li><a name="a1630"></a></span><span class="src-str">                        <span class="src-comm">//echo &quot;add_habtm_records: SQL: $sql&lt;br&gt;&quot;;</span></span></li>
<li><a name="a1631"></a></span><span class="src-str"><span class="src-comm"></span>                        <span class="src-var">$result</span> = <span class="src-var">$this</span></span><span class="src-sym">-&gt;</span><a href="../PHPonTrax/ActiveRecord.html#methodquery">query</a><span class="src-sym">(</span><span class="src-var">$sql</span><span class="src-sym">)</span><span class="src-sym">;</span></li>
<li><a name="a1632"></a>                        <span class="src-key">if </span><span class="src-sym">(</span><span class="src-var">$this</span><span class="src-sym">-&gt;</span><a href="../PHPonTrax/ActiveRecord.html#methodis_error">is_error</a><span class="src-sym">(</span><span class="src-var">$result</span><span class="src-sym">)) </span><span class="src-str"></span><span class="src-sym">{</span></span></li>
<li><a name="a1633"></a></span><span class="src-str">                            <span class="src-var">$this</span></span><span class="src-sym">-&gt;</span><a href="../PHPonTrax/ActiveRecord.html#methodraise">raise</a><span class="src-sym">(</span><span class="src-var">$result</span><span class="src-sym">-&gt;</span><span class="src-id">getMessage</span><span class="src-sym">(</span><span class="src-sym">))</span><span class="src-sym">;</span></li>
<li><a name="a1634"></a>                        </span><span class="src-str"><span class="src-sym">}</span></span></li>
<li><a name="a1635"></a></span><span class="src-str">                    <span class="src-sym">}</span></span></li>
<li><a name="a1636"></a></span><span class="src-str">                <span class="src-sym">}</span></span></li>
<li><a name="a1637"></a></span><span class="src-str">            <span class="src-sym">}</span></span></li>
<li><a name="a1638"></a></span><span class="src-str">        <span class="src-sym">}</span></span></li>
<li><a name="a1639"></a></span><span class="src-str">        <span class="src-key">return</span> <span class="src-id">true</span><span class="src-sym">;</span></span></li>
<li><a name="a1640"></a></span><span class="src-str">    <span class="src-sym">}</span></span></li>
<li><a name="a1641"></a>&nbsp;</li>
<li><a name="a1642"></a></span><span class="src-str">    /**</span></li>
<li><a name="a1643"></a></span><span class="src-str">     *</span></li>
<li><a name="a1644"></a></span><span class="src-str">     *  @uses is_error()</span></li>
<li><a name="a1645"></a></span><span class="src-str">     *  @uses query()</span></li>
<li><a name="a1646"></a></span><span class="src-str">     *  @throws {@link ActiveRecordError}</span></li>
<li><a name="a1647"></a></span><span class="src-str">     *  @todo Document this API</span></li>
<li><a name="a1648"></a></span><span class="src-str">     */</span></li>
<li><a name="a1649"></a></span><span class="src-str">    <span class="src-key">private</span> <span class="src-key">function</span> <span class="src-id">delete_habtm_records</span><span class="src-sym">(</span><span class="src-var">$this_foreign_value</span><span class="src-sym">)</span> <span class="src-sym">{</span></span></li>
<li><a name="a1650"></a></span><span class="src-str">        <span class="src-key">if</span><span class="src-sym">(</span><span class="src-var">$this_foreign_value</span> > <span class="src-num">0</span> &amp;&amp; <span class="src-id">count</span><span class="src-sym">(</span><span class="src-var">$this</span></span><span class="src-sym">-&gt;</span><a href="../PHPonTrax/ActiveRecord.html#var$habtm_attributes">habtm_attributes</a><span class="src-sym">) </span>&gt; <span class="src-num">0</span><span class="src-sym">) </span><span class="src-str"></span><span class="src-sym">{</span></span></li>
<li><a name="a1651"></a></span><span class="src-str">            <span class="src-id">reset</span><span class="src-sym">(</span><span class="src-var">$this</span></span><span class="src-sym">-&gt;</span><a href="../PHPonTrax/ActiveRecord.html#var$habtm_attributes">habtm_attributes</a><span class="src-sym">)</span><span class="src-sym">;</span></li>
<li><a name="a1652"></a>            <span class="src-key">foreach</span><span class="src-sym">(</span><span class="src-var">$this</span><span class="src-sym">-&gt;</span><a href="../PHPonTrax/ActiveRecord.html#var$habtm_attributes">habtm_attributes</a> <span class="src-key">as </span><span class="src-var">$other_table_name </span>=&gt; <span class="src-var">$values</span><span class="src-sym">) </span><span class="src-str"></span><span class="src-sym">{</span></span></li>
<li><a name="a1653"></a></span><span class="src-str">                <span class="src-var">$this</span></span><span class="src-sym">-&gt;</span><a href="../PHPonTrax/ActiveRecord.html#methoddelete_all_habtm_records">delete_all_habtm_records</a><span class="src-sym">(</span><span class="src-var">$other_table_name</span><span class="src-sym">, </span><span class="src-var">$this_foreign_value</span><span class="src-sym">)</span><span class="src-sym">;</span></li>
<li><a name="a1654"></a>            </span><span class="src-str"><span class="src-sym">}</span></span></li>
<li><a name="a1655"></a></span><span class="src-str">        <span class="src-sym">}</span></span></li>
<li><a name="a1656"></a></span><span class="src-str">        <span class="src-key">return</span> <span class="src-id">true</span><span class="src-sym">;</span></span></li>
<li><a name="a1657"></a></span><span class="src-str">    <span class="src-sym">}</span></span></li>
<li><a name="a1658"></a></span><span class="src-str">    </span></li>
<li><a name="a1659"></a></span><span class="src-str">    <span class="src-key">private</span> <span class="src-key">function</span> <span class="src-id">delete_all_habtm_records</span><span class="src-sym">(</span><span class="src-var">$other_table_name</span><span class="src-sym">,</span> <span class="src-var">$this_foreign_value</span><span class="src-sym">)</span> <span class="src-sym">{</span></span></li>
<li><a name="a1660"></a></span><span class="src-str">        <span class="src-key">if</span><span class="src-sym">(</span><span class="src-var">$other_table_name</span> &amp;&amp; <span class="src-var">$this_foreign_value</span> > <span class="src-num">0</span><span class="src-sym">)</span> <span class="src-sym">{</span></span></li>
<li><a name="a1661"></a></span><span class="src-str">            <span class="src-var">$habtm_table_name</span> = <span class="src-var">$this</span></span><span class="src-sym">-&gt;</span><a href="../PHPonTrax/ActiveRecord.html#methodget_join_table_name">get_join_table_name</a><span class="src-sym">(</span><span class="src-var">$this</span><span class="src-sym">-&gt;</span><a href="../PHPonTrax/ActiveRecord.html#var$table_name">table_name</a><span class="src-sym">,</span><span class="src-var">$other_table_name</span><span class="src-sym">)</span><span class="src-sym">;</span></li>
<li><a name="a1662"></a>            <span class="src-var">$this_foreign_key </span>= <span class="src-id">Inflector</span><span class="src-sym">::</span><span class="src-id">singularize</span><span class="src-sym">(</span><span class="src-var">$this</span><span class="src-sym">-&gt;</span><a href="../PHPonTrax/ActiveRecord.html#var$table_name">table_name</a><span class="src-sym">)</span>.<span class="src-str">&quot;_id&quot;</span><span class="src-sym">;</span></li>
<li><a name="a1663"></a>            <span class="src-var">$sql </span>= </span><span class="src-str"><span class="src-str">"</span><span class="src-id">DELETE</span> <span class="src-id">FROM</span> <span class="src-var">$habtm_table_name</span> <span class="src-id">WHERE</span> <span class="src-var">$this_foreign_key</span> = <span class="src-var">$this_foreign_value</span><span class="src-str">"</span><span class="src-sym">;</span></span></li>
<li><a name="a1664"></a></span><span class="src-str">            <span class="src-comm">//echo &quot;delete_all_habtm_records: SQL: $sql&lt;br&gt;&quot;;</span></span></li>
<li><a name="a1665"></a></span><span class="src-str"><span class="src-comm"></span>            <span class="src-var">$result</span> = <span class="src-var">$this</span></span><span class="src-sym">-&gt;</span><a href="../PHPonTrax/ActiveRecord.html#methodquery">query</a><span class="src-sym">(</span><span class="src-var">$sql</span><span class="src-sym">)</span><span class="src-sym">;</span></li>
<li><a name="a1666"></a>            <span class="src-key">if</span><span class="src-sym">(</span><span class="src-var">$this</span><span class="src-sym">-&gt;</span><a href="../PHPonTrax/ActiveRecord.html#methodis_error">is_error</a><span class="src-sym">(</span><span class="src-var">$result</span><span class="src-sym">)) </span><span class="src-str"></span><span class="src-sym">{</span></span></li>
<li><a name="a1667"></a></span><span class="src-str">                <span class="src-var">$this</span></span><span class="src-sym">-&gt;</span><a href="../PHPonTrax/ActiveRecord.html#methodraise">raise</a><span class="src-sym">(</span><span class="src-var">$result</span><span class="src-sym">-&gt;</span><span class="src-id">getMessage</span><span class="src-sym">(</span><span class="src-sym">))</span><span class="src-sym">;</span></li>
<li><a name="a1668"></a>            </span><span class="src-str"><span class="src-sym">}</span>            </span></li>
<li><a name="a1669"></a></span><span class="src-str">        <span class="src-sym">}</span></span></li>
<li><a name="a1670"></a></span><span class="src-str">    <span class="src-sym">}</span></span></li>
<li><a name="a1671"></a>&nbsp;</li>
<li><a name="a1672"></a></span><span class="src-str">    /**</span></li>
<li><a name="a1673"></a></span><span class="src-str">     *  Apply automatic timestamp updates</span></li>
<li><a name="a1674"></a></span><span class="src-str">     *</span></li>
<li><a name="a1675"></a></span><span class="src-str">     *  If automatic timestamps are in effect (as indicated by</span></li>
<li><a name="a1676"></a></span><span class="src-str">     *  {@link $auto_timestamps} == true) and the column named in the</span></li>
<li><a name="a1677"></a></span><span class="src-str">     *  $field argument is of type &quot;timestamp&quot; and matches one of the</span></li>
<li><a name="a1678"></a></span><span class="src-str">     *  names in {@link auto_create_timestamps} or {@link</span></li>
<li><a name="a1679"></a></span><span class="src-str">     *  auto_update_timestamps}(as selected by {@link $new_record}),</span></li>
<li><a name="a1680"></a></span><span class="src-str">     *  then return the current date and  time as a string formatted</span></li>
<li><a name="a1681"></a></span><span class="src-str">     *  to insert in the database.  Otherwise return $value.</span></li>
<li><a name="a1682"></a></span><span class="src-str">     *  @uses $new_record</span></li>
<li><a name="a1683"></a></span><span class="src-str">     *  @uses $content_columns</span></li>
<li><a name="a1684"></a></span><span class="src-str">     *  @uses $auto_timestamps</span></li>
<li><a name="a1685"></a></span><span class="src-str">     *  @uses $auto_create_timestamps</span></li>
<li><a name="a1686"></a></span><span class="src-str">     *  @uses $auto_update_timestamps</span></li>
<li><a name="a1687"></a></span><span class="src-str">     *  @param string $field Name of a column in the table</span></li>
<li><a name="a1688"></a></span><span class="src-str">     *  @param mixed $value Value to return if $field is not an</span></li>
<li><a name="a1689"></a></span><span class="src-str">     *                      automatic timestamp column</span></li>
<li><a name="a1690"></a></span><span class="src-str">     *  @return mixed Current date and time or $value</span></li>
<li><a name="a1691"></a></span><span class="src-str">     */</span></li>
<li><a name="a1692"></a></span><span class="src-str">    <span class="src-key">private</span> <span class="src-key">function</span> <span class="src-id">check_datetime</span><span class="src-sym">(</span><span class="src-var">$field</span><span class="src-sym">,</span> <span class="src-var">$value</span><span class="src-sym">)</span> <span class="src-sym">{</span></span></li>
<li><a name="a1693"></a></span><span class="src-str">        <span class="src-key">if</span><span class="src-sym">(</span><span class="src-var">$this</span></span><span class="src-sym">-&gt;</span><a href="../PHPonTrax/ActiveRecord.html#var$auto_timestamps">auto_timestamps</a><span class="src-sym">) </span><span class="src-str"></span><span class="src-sym">{</span></span></li>
<li><a name="a1694"></a></span><span class="src-str">            <span class="src-key">if</span><span class="src-sym">(</span><span class="src-id">is_array</span><span class="src-sym">(</span><span class="src-var">$this</span></span><span class="src-sym">-&gt;</span><a href="../PHPonTrax/ActiveRecord.html#var$content_columns">content_columns</a><span class="src-sym">)) </span><span class="src-str"></span><span class="src-sym">{</span></span></li>
<li><a name="a1695"></a></span><span class="src-str">                <span class="src-key">foreach</span><span class="src-sym">(</span><span class="src-var">$this</span></span><span class="src-sym">-&gt;</span><a href="../PHPonTrax/ActiveRecord.html#var$content_columns">content_columns</a> <span class="src-key">as </span><span class="src-var">$field_info</span><span class="src-sym">) </span><span class="src-str"></span><span class="src-sym">{</span></span></li>
<li><a name="a1696"></a></span><span class="src-str">                    <span class="src-key">if</span><span class="src-sym">((</span><span class="src-var">$field_info</span><span class="src-sym">[</span><span class="src-str">'name'</span><span class="src-sym">]</span> == <span class="src-var">$field</span><span class="src-sym">)</span> &amp;&amp; <span class="src-id">stristr</span><span class="src-sym">(</span><span class="src-var">$field_info</span><span class="src-sym">[</span><span class="src-str">'type'</span><span class="src-sym">]</span><span class="src-sym">,</span> <span class="src-str">&quot;date&quot;</span><span class="src-sym">))</span> <span class="src-sym">{</span></span></li>
<li><a name="a1697"></a></span><span class="src-str">                        <span class="src-var">$format</span> = <span class="src-sym">(</span><span class="src-var">$field_info</span><span class="src-sym">[</span><span class="src-str">'type'</span><span class="src-sym">]</span> == <span class="src-str">&quot;date&quot;</span><span class="src-sym">)</span> ? <span class="src-var">$this</span></span><span class="src-sym">-&gt;</span><a href="../PHPonTrax/ActiveRecord.html#var$date_format">date_format</a> : </span><span class="src-str"><span class="src-str">"</span></span>{<span class="src-var">$this</span><span class="src-sym">-&gt;</span><a href="../PHPonTrax/ActiveRecord.html#var$date_format">date_format</a><span class="src-sym">} </span>{<span class="src-var">$this</span><span class="src-sym">-&gt;</span><a href="../PHPonTrax/ActiveRecord.html#var$time_format">time_format</a><span class="src-sym">}</span><span class="src-str"></span><span class="src-str">"</span><span class="src-sym">;</span></span></li>
<li><a name="a1698"></a></span><span class="src-str">                        <span class="src-key">if</span><span class="src-sym">(</span><span class="src-var">$this</span></span><span class="src-sym">-&gt;</span><a href="../PHPonTrax/ActiveRecord.html#var$new_record">new_record</a><span class="src-sym">) </span><span class="src-str"></span><span class="src-sym">{</span></span></li>
<li><a name="a1699"></a></span><span class="src-str">                            <span class="src-key">if</span><span class="src-sym">(</span><span class="src-id">in_array</span><span class="src-sym">(</span><span class="src-var">$field</span><span class="src-sym">,</span> <span class="src-var">$this</span></span><span class="src-sym">-&gt;</span><a href="../PHPonTrax/ActiveRecord.html#var$auto_create_timestamps">auto_create_timestamps</a><span class="src-sym">)) </span><span class="src-str"></span><span class="src-sym">{</span></span></li>
<li><a name="a1700"></a></span><span class="src-str">                                <span class="src-key">return</span> <span class="src-id">date</span><span class="src-sym">(</span><span class="src-var">$format</span><span class="src-sym">)</span><span class="src-sym">;</span></span></li>
<li><a name="a1701"></a></span><span class="src-str">                            <span class="src-sym">}</span> <span class="src-key">elseif</span><span class="src-sym">(</span><span class="src-var">$this</span></span><span class="src-sym">-&gt;</span><a href="../PHPonTrax/ActiveRecord.html#var$preserve_null_dates">preserve_null_dates</a> &amp;&amp; <span class="src-id">is_null</span><span class="src-sym">(</span><span class="src-var">$value</span><span class="src-sym">) </span>&amp;&amp; <span class="src-sym">!</span><span class="src-id">stristr</span><span class="src-sym">(</span><span class="src-var">$field_info</span><span class="src-sym">[</span><span class="src-str">'flags'</span><span class="src-sym">]</span><span class="src-sym">, </span><span class="src-str">&quot;not_null&quot;</span><span class="src-sym">)) </span><span class="src-str"></span><span class="src-sym">{</span></span></li>
<li><a name="a1702"></a></span><span class="src-str">                                <span class="src-key">return</span> <span class="src-str">'NULL'</span><span class="src-sym">;</span>    </span></li>
<li><a name="a1703"></a></span><span class="src-str">                            <span class="src-sym">}</span></span></li>
<li><a name="a1704"></a></span><span class="src-str">                        <span class="src-sym">}</span> <span class="src-key">elseif</span><span class="src-sym">(</span><span class="src-sym">!</span><span class="src-var">$this</span></span><span class="src-sym">-&gt;</span><a href="../PHPonTrax/ActiveRecord.html#var$new_record">new_record</a><span class="src-sym">) </span><span class="src-str"></span><span class="src-sym">{</span></span></li>
<li><a name="a1705"></a></span><span class="src-str">                            <span class="src-key">if</span><span class="src-sym">(</span><span class="src-id">in_array</span><span class="src-sym">(</span><span class="src-var">$field</span><span class="src-sym">,</span> <span class="src-var">$this</span></span><span class="src-sym">-&gt;</span><a href="../PHPonTrax/ActiveRecord.html#var$auto_update_timestamps">auto_update_timestamps</a><span class="src-sym">)) </span><span class="src-str"></span><span class="src-sym">{</span></span></li>
<li><a name="a1706"></a></span><span class="src-str">                                <span class="src-key">return</span> <span class="src-id">date</span><span class="src-sym">(</span><span class="src-var">$format</span><span class="src-sym">)</span><span class="src-sym">;</span></span></li>
<li><a name="a1707"></a></span><span class="src-str">                            <span class="src-sym">}</span> <span class="src-key">elseif</span><span class="src-sym">(</span><span class="src-var">$this</span></span><span class="src-sym">-&gt;</span><a href="../PHPonTrax/ActiveRecord.html#var$preserve_null_dates">preserve_null_dates</a> &amp;&amp; <span class="src-id">is_null</span><span class="src-sym">(</span><span class="src-var">$value</span><span class="src-sym">) </span>&amp;&amp; <span class="src-sym">!</span><span class="src-id">stristr</span><span class="src-sym">(</span><span class="src-var">$field_info</span><span class="src-sym">[</span><span class="src-str">'flags'</span><span class="src-sym">]</span><span class="src-sym">, </span><span class="src-str">&quot;not_null&quot;</span><span class="src-sym">)) </span><span class="src-str"></span><span class="src-sym">{</span></span></li>
<li><a name="a1708"></a></span><span class="src-str">                                <span class="src-key">return</span> <span class="src-str">'NULL'</span><span class="src-sym">;</span>    </span></li>
<li><a name="a1709"></a></span><span class="src-str">                            <span class="src-sym">}</span></span></li>
<li><a name="a1710"></a></span><span class="src-str">                        <span class="src-sym">}</span></span></li>
<li><a name="a1711"></a></span><span class="src-str">                    <span class="src-sym">}</span>  </span></li>
<li><a name="a1712"></a></span><span class="src-str">                <span class="src-sym">}</span></span></li>
<li><a name="a1713"></a></span><span class="src-str">            <span class="src-sym">}</span></span></li>
<li><a name="a1714"></a></span><span class="src-str">        <span class="src-sym">}</span></span></li>
<li><a name="a1715"></a></span><span class="src-str">        <span class="src-key">return</span> <span class="src-var">$value</span><span class="src-sym">;</span></span></li>
<li><a name="a1716"></a></span><span class="src-str">    <span class="src-sym">}</span></span></li>
<li><a name="a1717"></a>&nbsp;</li>
<li><a name="a1718"></a></span><span class="src-str">    /**</span></li>
<li><a name="a1719"></a></span><span class="src-str">     *  Update object attributes from list in argument</span></li>
<li><a name="a1720"></a></span><span class="src-str">     *</span></li>
<li><a name="a1721"></a></span><span class="src-str">     *  The elements of $attributes are parsed and assigned to</span></li>
<li><a name="a1722"></a></span><span class="src-str">     *  attributes of the ActiveRecord object.  Date/time fields are</span></li>
<li><a name="a1723"></a></span><span class="src-str">     *  treated according to the</span></li>
<li><a name="a1724"></a></span><span class="src-str">     *  {@tutorial PHPonTrax/naming.pkg#naming.naming_forms}.</span></li>
<li><a name="a1725"></a></span><span class="src-str">     *  @param string[] $attributes List of name =&gt; value pairs giving</span></li>
<li><a name="a1726"></a></span><span class="src-str">     *    name and value of attributes to set.</span></li>
<li><a name="a1727"></a></span><span class="src-str">     *  @uses $auto_save_associations</span></li>
<li><a name="a1728"></a></span><span class="src-str">     *  @todo Figure out and document how datetime fields work</span></li>
<li><a name="a1729"></a></span><span class="src-str">     */</span></li>
<li><a name="a1730"></a></span><span class="src-str">    <span class="src-key">function</span> <span class="src-id">update_attributes</span><span class="src-sym">(</span><span class="src-var">$attributes</span><span class="src-sym">)</span> <span class="src-sym">{</span></span></li>
<li><a name="a1731"></a></span><span class="src-str">        <span class="src-comm">//error_log('update_attributes()');</span></span></li>
<li><a name="a1732"></a></span><span class="src-str"><span class="src-comm"></span></span></li>
<li><a name="a1733"></a></span><span class="src-str">        <span class="src-comm">//  Test each attribute to be updated</span></span></li>
<li><a name="a1734"></a></span><span class="src-str"><span class="src-comm"></span>        <span class="src-comm">//  and process according to its type</span></span></li>
<li><a name="a1735"></a></span><span class="src-str"><span class="src-comm"></span>        <span class="src-key">foreach</span><span class="src-sym">(</span><span class="src-var">$attributes</span> <span class="src-key">as</span> <span class="src-var">$field</span> =&gt; <span class="src-var">$value</span><span class="src-sym">)</span> <span class="src-sym">{</span></span></li>
<li><a name="a1736"></a></span><span class="src-str">            <span class="src-comm"># datetime / date parts check</span></span></li>
<li><a name="a1737"></a></span><span class="src-str"><span class="src-comm"></span>            <span class="src-key">if</span><span class="src-sym">(</span><span class="src-id">preg_match</span><span class="src-sym">(</span><span class="src-str">'/^\w+\(.*i\)$/i'</span><span class="src-sym">,</span> <span class="src-var">$field</span><span class="src-sym">))</span> <span class="src-sym">{</span></span></li>
<li><a name="a1738"></a>&nbsp;</li>
<li><a name="a1739"></a></span><span class="src-str">                <span class="src-comm">//  The name of this attribute ends in &quot;(?i)&quot;</span></span></li>
<li><a name="a1740"></a></span><span class="src-str"><span class="src-comm"></span>                <span class="src-comm">//  indicating that it's part of a date or time</span></span></li>
<li><a name="a1741"></a></span><span class="src-str"><span class="src-comm"></span></span></li>
<li><a name="a1742"></a></span><span class="src-str">                <span class="src-comm">//  Accumulate all the pieces of a date and time in</span></span></li>
<li><a name="a1743"></a></span><span class="src-str"><span class="src-comm"></span>                <span class="src-comm">//  array $datetime_key.  The keys in the array are</span></span></li>
<li><a name="a1744"></a></span><span class="src-str"><span class="src-comm"></span>                <span class="src-comm">//  the names of date/time attributes with the final</span></span></li>
<li><a name="a1745"></a></span><span class="src-str"><span class="src-comm"></span>                <span class="src-comm">//  &quot;(?i)&quot; stripped off.</span></span></li>
<li><a name="a1746"></a></span><span class="src-str"><span class="src-comm"></span>                <span class="src-var">$datetime_key</span> = <span class="src-id">substr</span><span class="src-sym">(</span><span class="src-var">$field</span><span class="src-sym">,</span> <span class="src-num">0</span><span class="src-sym">,</span> <span class="src-id">strpos</span><span class="src-sym">(</span><span class="src-var">$field</span><span class="src-sym">,</span> <span class="src-str">&quot;(&quot;</span><span class="src-sym">))</span><span class="src-sym">;</span></span></li>
<li><a name="a1747"></a></span><span class="src-str">                <span class="src-key">if</span><span class="src-sym">(</span> <span class="src-sym">!</span>isset<span class="src-sym">(</span><span class="src-var">$old_datetime_key</span><span class="src-sym">)</span></span></li>
<li><a name="a1748"></a></span><span class="src-str">                    || <span class="src-sym">(</span><span class="src-var">$datetime_key</span> != <span class="src-var">$old_datetime_key</span><span class="src-sym">))</span> <span class="src-sym">{</span></span></li>
<li><a name="a1749"></a>&nbsp;</li>
<li><a name="a1750"></a></span><span class="src-str">                    <span class="src-comm">//  This value of $datetime_key hasn't been seen</span></span></li>
<li><a name="a1751"></a></span><span class="src-str"><span class="src-comm"></span>                    <span class="src-comm">//  before, so remember it.</span></span></li>
<li><a name="a1752"></a></span><span class="src-str"><span class="src-comm"></span>                    <span class="src-var">$old_datetime_key</span> = <span class="src-var">$datetime_key</span><span class="src-sym">;</span>                     </span></li>
<li><a name="a1753"></a>&nbsp;</li>
<li><a name="a1754"></a></span><span class="src-str">                    <span class="src-comm">//  $datetime_value accumulates the pieces of the</span></span></li>
<li><a name="a1755"></a></span><span class="src-str"><span class="src-comm"></span>                    <span class="src-comm">//  date/time attribute $datetime_key</span></span></li>
<li><a name="a1756"></a></span><span class="src-str"><span class="src-comm"></span>                    <span class="src-var">$datetime_value</span> = <span class="src-str">&quot;&quot;</span><span class="src-sym">;</span>   </span></li>
<li><a name="a1757"></a></span><span class="src-str">                <span class="src-sym">}</span> </span></li>
<li><a name="a1758"></a>&nbsp;</li>
<li><a name="a1759"></a></span><span class="src-str">                <span class="src-comm">//  Concatentate pieces of the attribute's value</span></span></li>
<li><a name="a1760"></a></span><span class="src-str"><span class="src-comm"></span>                <span class="src-comm">//  FIXME: this only works if the array elements</span></span></li>
<li><a name="a1761"></a></span><span class="src-str"><span class="src-comm"></span>                <span class="src-comm">//  are sorted by key.  Is this guaranteed?</span></span></li>
<li><a name="a1762"></a></span><span class="src-str"><span class="src-comm"></span>                <span class="src-key">if</span><span class="src-sym">(</span><span class="src-id">strstr</span><span class="src-sym">(</span><span class="src-var">$field</span><span class="src-sym">,</span> <span class="src-str">&quot;2i&quot;</span><span class="src-sym">)</span> || <span class="src-id">strstr</span><span class="src-sym">(</span><span class="src-var">$field</span><span class="src-sym">,</span> <span class="src-str">&quot;3i&quot;</span><span class="src-sym">))</span> <span class="src-sym">{</span></span></li>
<li><a name="a1763"></a></span><span class="src-str">                    <span class="src-var">$datetime_value</span> .= <span class="src-str">&quot;-&quot;</span>.<span class="src-var">$value</span><span class="src-sym">;</span>    </span></li>
<li><a name="a1764"></a></span><span class="src-str">                <span class="src-sym">}</span> <span class="src-key">elseif</span><span class="src-sym">(</span><span class="src-id">strstr</span><span class="src-sym">(</span><span class="src-var">$field</span><span class="src-sym">,</span> <span class="src-str">&quot;4i&quot;</span><span class="src-sym">))</span> <span class="src-sym">{</span></span></li>
<li><a name="a1765"></a></span><span class="src-str">                    <span class="src-var">$datetime_value</span> .= <span class="src-str">&quot; &quot;</span>.<span class="src-var">$value</span><span class="src-sym">;</span>        </span></li>
<li><a name="a1766"></a></span><span class="src-str">                <span class="src-sym">}</span> <span class="src-key">elseif</span><span class="src-sym">(</span><span class="src-id">strstr</span><span class="src-sym">(</span><span class="src-var">$field</span><span class="src-sym">,</span> <span class="src-str">&quot;5i&quot;</span><span class="src-sym">))</span> <span class="src-sym">{</span></span></li>
<li><a name="a1767"></a></span><span class="src-str">                    <span class="src-var">$datetime_value</span> .= <span class="src-str">&quot;:&quot;</span>.<span class="src-var">$value</span><span class="src-sym">;</span>        </span></li>
<li><a name="a1768"></a></span><span class="src-str">                <span class="src-sym">}</span> <span class="src-key">else</span> <span class="src-sym">{</span></span></li>
<li><a name="a1769"></a></span><span class="src-str">                    <span class="src-var">$datetime_value</span> .= <span class="src-var">$value</span><span class="src-sym">;</span>    </span></li>
<li><a name="a1770"></a></span><span class="src-str">                <span class="src-sym">}</span>  </span></li>
<li><a name="a1771"></a></span><span class="src-str">                <span class="src-var">$datetime_fields</span><span class="src-sym">[</span><span class="src-var">$old_datetime_key</span><span class="src-sym">]</span> = <span class="src-var">$datetime_value</span><span class="src-sym">;</span>     </span></li>
<li><a name="a1772"></a></span><span class="src-str">                <span class="src-comm"># this elseif checks if first its an object if its parent is ActiveRecord            </span></span></li>
<li><a name="a1773"></a></span><span class="src-str"><span class="src-comm"></span>            <span class="src-sym">}</span> <span class="src-key">elseif</span><span class="src-sym">(</span><span class="src-id">is_object</span><span class="src-sym">(</span><span class="src-var">$value</span><span class="src-sym">)</span> &amp;&amp; <span class="src-id">get_parent_class</span><span class="src-sym">(</span><span class="src-var">$value</span><span class="src-sym">)</span> == __CLASS__ &amp;&amp; <span class="src-var">$this</span></span><span class="src-sym">-&gt;</span><a href="../PHPonTrax/ActiveRecord.html#var$auto_save_associations">auto_save_associations</a><span class="src-sym">) </span><span class="src-str"></span><span class="src-sym">{</span></span></li>
<li><a name="a1774"></a></span><span class="src-str">                <span class="src-key">if</span><span class="src-sym">(</span><span class="src-var">$association_type</span> = <span class="src-var">$this</span></span><span class="src-sym">-&gt;</span><a href="../PHPonTrax/ActiveRecord.html#methodget_association_type">get_association_type</a><span class="src-sym">(</span><span class="src-var">$field</span><span class="src-sym">)) </span><span class="src-str"></span><span class="src-sym">{</span></span></li>
<li><a name="a1775"></a></span><span class="src-str">                    <span class="src-var">$this</span></span><span class="src-sym">-&gt;</span><a href="../PHPonTrax/ActiveRecord.html#var$save_associations">save_associations</a><span class="src-sym">[</span><span class="src-var">$association_type</span><span class="src-sym">]</span><span class="src-sym">[</span><span class="src-sym">] </span>= <span class="src-var">$value</span><span class="src-sym">;</span></li>
<li><a name="a1776"></a>                    <span class="src-key">if</span><span class="src-sym">(</span><span class="src-var">$association_type </span>== <span class="src-str">&quot;belongs_to&quot;</span><span class="src-sym">) </span><span class="src-str"></span><span class="src-sym">{</span></span></li>
<li><a name="a1777"></a></span><span class="src-str">                        <span class="src-var">$foreign_key</span> = <span class="src-id">Inflector</span><span class="src-sym">::</span><span class="src-id">singularize</span><span class="src-sym">(</span><span class="src-var">$value</span></span><span class="src-sym">-&gt;</span><span class="src-id">table_name</span><span class="src-sym">)</span>.<span class="src-str">&quot;_id&quot;</span><span class="src-sym">;</span></li>
<li><a name="a1778"></a>                        <span class="src-var">$this</span><span class="src-sym">-&gt;</span><span class="src-var">$foreign_key </span>= <span class="src-var">$value</span><span class="src-sym">-&gt;</span><span class="src-id">id</span><span class="src-sym">; </span></li>
<li><a name="a1779"></a>                    </span><span class="src-str"><span class="src-sym">}</span></span></li>
<li><a name="a1780"></a></span><span class="src-str">                <span class="src-sym">}</span></span></li>
<li><a name="a1781"></a></span><span class="src-str">                <span class="src-comm"># this elseif checks if its an array of objects and if its parent is ActiveRecord                </span></span></li>
<li><a name="a1782"></a></span><span class="src-str"><span class="src-comm"></span>            <span class="src-sym">}</span> <span class="src-key">elseif</span><span class="src-sym">(</span><span class="src-id">is_array</span><span class="src-sym">(</span><span class="src-var">$value</span><span class="src-sym">)</span> &amp;&amp; <span class="src-var">$this</span></span><span class="src-sym">-&gt;</span><a href="../PHPonTrax/ActiveRecord.html#var$auto_save_associations">auto_save_associations</a><span class="src-sym">) </span><span class="src-str"></span><span class="src-sym">{</span></span></li>
<li><a name="a1783"></a></span><span class="src-str">                <span class="src-key">if</span><span class="src-sym">(</span><span class="src-var">$association_type</span> = <span class="src-var">$this</span></span><span class="src-sym">-&gt;</span><a href="../PHPonTrax/ActiveRecord.html#methodget_association_type">get_association_type</a><span class="src-sym">(</span><span class="src-var">$field</span><span class="src-sym">)) </span><span class="src-str"></span><span class="src-sym">{</span></span></li>
<li><a name="a1784"></a></span><span class="src-str">                    <span class="src-var">$this</span></span><span class="src-sym">-&gt;</span><a href="../PHPonTrax/ActiveRecord.html#var$save_associations">save_associations</a><span class="src-sym">[</span><span class="src-var">$association_type</span><span class="src-sym">]</span><span class="src-sym">[</span><span class="src-sym">] </span>= <span class="src-var">$value</span><span class="src-sym">;</span></li>
<li><a name="a1785"></a>                </span><span class="src-str"><span class="src-sym">}</span></span></li>
<li><a name="a1786"></a></span><span class="src-str">            <span class="src-sym">}</span> <span class="src-key">else</span> <span class="src-sym">{</span></span></li>
<li><a name="a1787"></a>&nbsp;</li>
<li><a name="a1788"></a></span><span class="src-str">                <span class="src-comm">//  Just a simple attribute, copy it</span></span></li>
<li><a name="a1789"></a></span><span class="src-str"><span class="src-comm"></span>                <span class="src-var">$this</span></span><span class="src-sym">-&gt;</span><span class="src-var">$field </span>= <span class="src-var">$value</span><span class="src-sym">;</span></li>
<li><a name="a1790"></a>            </span><span class="src-str"><span class="src-sym">}</span></span></li>
<li><a name="a1791"></a></span><span class="src-str">        <span class="src-sym">}</span></span></li>
<li><a name="a1792"></a>&nbsp;</li>
<li><a name="a1793"></a></span><span class="src-str">        <span class="src-comm">//  If any date/time fields were found, assign the</span></span></li>
<li><a name="a1794"></a></span><span class="src-str"><span class="src-comm"></span>        <span class="src-comm">//  accumulated values to corresponding attributes</span></span></li>
<li><a name="a1795"></a></span><span class="src-str"><span class="src-comm"></span>        <span class="src-key">if</span><span class="src-sym">(</span>isset<span class="src-sym">(</span><span class="src-var">$datetime_fields</span><span class="src-sym">)</span></span></li>
<li><a name="a1796"></a></span><span class="src-str">           &amp;&amp; <span class="src-id">is_array</span><span class="src-sym">(</span><span class="src-var">$datetime_fields</span><span class="src-sym">))</span> <span class="src-sym">{</span></span></li>
<li><a name="a1797"></a></span><span class="src-str">            <span class="src-key">foreach</span><span class="src-sym">(</span><span class="src-var">$datetime_fields</span> <span class="src-key">as</span> <span class="src-var">$field</span> =&gt; <span class="src-var">$value</span><span class="src-sym">)</span> <span class="src-sym">{</span></span></li>
<li><a name="a1798"></a></span><span class="src-str">                <span class="src-comm">//error_log(&quot;$field = $value&quot;);</span></span></li>
<li><a name="a1799"></a></span><span class="src-str"><span class="src-comm"></span>                <span class="src-var">$this</span></span><span class="src-sym">-&gt;</span><span class="src-var">$field </span>= <span class="src-var">$value</span><span class="src-sym">;    </span></li>
<li><a name="a1800"></a>            </span><span class="src-str"><span class="src-sym">}</span>    </span></li>
<li><a name="a1801"></a></span><span class="src-str">        <span class="src-sym">}</span></span></li>
<li><a name="a1802"></a></span><span class="src-str">        <span class="src-var">$this</span></span><span class="src-sym">-&gt;</span><a href="../PHPonTrax/ActiveRecord.html#methodset_habtm_attributes">set_habtm_attributes</a><span class="src-sym">(</span><span class="src-var">$attributes</span><span class="src-sym">)</span><span class="src-sym">;</span></li>
<li><a name="a1803"></a>    </span><span class="src-str"><span class="src-sym">}</span></span></li>
<li><a name="a1804"></a>&nbsp;</li>
<li><a name="a1805"></a></span><span class="src-str">    /**</span></li>
<li><a name="a1806"></a></span><span class="src-str">     *  Return pairs of column-name:column-value</span></li>
<li><a name="a1807"></a></span><span class="src-str">     *</span></li>
<li><a name="a1808"></a></span><span class="src-str">     *  Return the contents of the object as an array of elements</span></li>
<li><a name="a1809"></a></span><span class="src-str">     *  where the key is the column name and the value is the column</span></li>
<li><a name="a1810"></a></span><span class="src-str">     *  value.  Relies on a previous call to</span></li>
<li><a name="a1811"></a></span><span class="src-str">     *  {@link set_content_columns()} for information about the format</span></li>
<li><a name="a1812"></a></span><span class="src-str">     *  of a row in the table.</span></li>
<li><a name="a1813"></a></span><span class="src-str">     *  @uses $content_columns</span></li>
<li><a name="a1814"></a></span><span class="src-str">     *  @see set_content_columns</span></li>
<li><a name="a1815"></a></span><span class="src-str">     *  @see quoted_attributes()</span></li>
<li><a name="a1816"></a></span><span class="src-str">     */</span></li>
<li><a name="a1817"></a></span><span class="src-str">    <span class="src-key">function</span> <span class="src-id">get_attributes</span><span class="src-sym">(</span><span class="src-sym">)</span> <span class="src-sym">{</span></span></li>
<li><a name="a1818"></a></span><span class="src-str">        <span class="src-var">$attributes</span> = <span class="src-key">array</span><span class="src-sym">(</span><span class="src-sym">)</span><span class="src-sym">;</span></span></li>
<li><a name="a1819"></a></span><span class="src-str">        <span class="src-key">if</span><span class="src-sym">(</span><span class="src-id">is_array</span><span class="src-sym">(</span><span class="src-var">$this</span></span><span class="src-sym">-&gt;</span><a href="../PHPonTrax/ActiveRecord.html#var$content_columns">content_columns</a><span class="src-sym">)) </span><span class="src-str"></span><span class="src-sym">{</span></span></li>
<li><a name="a1820"></a></span><span class="src-str">            <span class="src-key">foreach</span><span class="src-sym">(</span><span class="src-var">$this</span></span><span class="src-sym">-&gt;</span><a href="../PHPonTrax/ActiveRecord.html#var$content_columns">content_columns</a> <span class="src-key">as </span><span class="src-var">$column</span><span class="src-sym">) </span><span class="src-str"></span><span class="src-sym">{</span></span></li>
<li><a name="a1821"></a></span><span class="src-str">                <span class="src-comm">//echo &quot;attribute: $info[name] -&gt; {$this-&gt;$info[name]}&lt;br&gt;&quot;;</span></span></li>
<li><a name="a1822"></a></span><span class="src-str"><span class="src-comm"></span>                <span class="src-var">$attributes</span><span class="src-sym">[</span><span class="src-var">$column</span><span class="src-sym">[</span><span class="src-str">'name'</span><span class="src-sym">]]</span> = <span class="src-var">$this</span></span><span class="src-sym">-&gt;</span><span class="src-var">$column</span><span class="src-sym">[</span><span class="src-str">'name'</span><span class="src-sym">]</span><span class="src-sym">;</span></li>
<li><a name="a1823"></a>            </span><span class="src-str"><span class="src-sym">}</span></span></li>
<li><a name="a1824"></a></span><span class="src-str">        <span class="src-sym">}</span></span></li>
<li><a name="a1825"></a></span><span class="src-str">        <span class="src-key">return</span> <span class="src-var">$attributes</span><span class="src-sym">;</span></span></li>
<li><a name="a1826"></a></span><span class="src-str">    <span class="src-sym">}</span></span></li>
<li><a name="a1827"></a>&nbsp;</li>
<li><a name="a1828"></a></span><span class="src-str">    /**</span></li>
<li><a name="a1829"></a></span><span class="src-str">     *  Return pairs of column-name:quoted-column-value</span></li>
<li><a name="a1830"></a></span><span class="src-str">     *</span></li>
<li><a name="a1831"></a></span><span class="src-str">     *  Return pairs of column-name:quoted-column-value where the key</span></li>
<li><a name="a1832"></a></span><span class="src-str">     *  is the column name and the value is the column value with</span></li>
<li><a name="a1833"></a></span><span class="src-str">     *  automatic timestamp updating applied and characters special to</span></li>
<li><a name="a1834"></a></span><span class="src-str">     *  SQL quoted.</span></li>
<li><a name="a1835"></a></span><span class="src-str">     *  </span></li>
<li><a name="a1836"></a></span><span class="src-str">     *  If $attributes is null or omitted, return all columns as</span></li>
<li><a name="a1837"></a></span><span class="src-str">     *  currently stored in {@link content_columns()}.  Otherwise,</span></li>
<li><a name="a1838"></a></span><span class="src-str">     *  return the name:value pairs in $attributes.</span></li>
<li><a name="a1839"></a></span><span class="src-str">     *  @param string[] $attributes Name:value pairs to return.</span></li>
<li><a name="a1840"></a></span><span class="src-str">     *    If null or omitted, return the column names and values</span></li>
<li><a name="a1841"></a></span><span class="src-str">     *    of the object as stored in $content_columns.</span></li>
<li><a name="a1842"></a></span><span class="src-str">     *  @return string[] </span></li>
<li><a name="a1843"></a></span><span class="src-str">     *  @uses get_attributes()</span></li>
<li><a name="a1844"></a></span><span class="src-str">     *  @see set_content_columns()</span></li>
<li><a name="a1845"></a></span><span class="src-str">     */</span></li>
<li><a name="a1846"></a></span><span class="src-str">    <span class="src-key">function</span> <span class="src-id">quoted_attributes</span><span class="src-sym">(</span><span class="src-var">$attributes</span> = <span class="src-id">null</span><span class="src-sym">)</span> <span class="src-sym">{</span></span></li>
<li><a name="a1847"></a></span><span class="src-str">        <span class="src-key">if</span><span class="src-sym">(</span><span class="src-id">is_null</span><span class="src-sym">(</span><span class="src-var">$attributes</span><span class="src-sym">))</span> <span class="src-sym">{</span></span></li>
<li><a name="a1848"></a></span><span class="src-str">            <span class="src-var">$attributes</span> = <span class="src-var">$this</span></span><span class="src-sym">-&gt;</span><a href="../PHPonTrax/ActiveRecord.html#methodget_attributes">get_attributes</a><span class="src-sym">(</span><span class="src-sym">)</span><span class="src-sym">;</span></li>
<li><a name="a1849"></a>        </span><span class="src-str"><span class="src-sym">}</span></span></li>
<li><a name="a1850"></a></span><span class="src-str">        <span class="src-var">$return</span> = <span class="src-key">array</span><span class="src-sym">(</span><span class="src-sym">)</span><span class="src-sym">;</span></span></li>
<li><a name="a1851"></a></span><span class="src-str">        <span class="src-key">foreach</span> <span class="src-sym">(</span><span class="src-var">$attributes</span> <span class="src-key">as</span> <span class="src-var">$key</span> =&gt; <span class="src-var">$value</span><span class="src-sym">)</span> <span class="src-sym">{</span></span></li>
<li><a name="a1852"></a></span><span class="src-str">            <span class="src-var">$value</span> = <span class="src-var">$this</span></span><span class="src-sym">-&gt;</span><a href="../PHPonTrax/ActiveRecord.html#methodcheck_datetime">check_datetime</a><span class="src-sym">(</span><span class="src-var">$key</span><span class="src-sym">, </span><span class="src-var">$value</span><span class="src-sym">)</span><span class="src-sym">;</span></li>
<li><a name="a1853"></a>            <span class="src-comm"># If the value isn't a function or null quote it.</span></li>
<li><a name="a1854"></a>            <span class="src-key">if</span><span class="src-sym">(</span><span class="src-sym">!</span><span class="src-sym">(</span><span class="src-id">preg_match</span><span class="src-sym">(</span><span class="src-str">'/^\w+\(.*\)$/U'</span><span class="src-sym">, </span><span class="src-var">$value</span><span class="src-sym">)) </span>&amp;&amp; <span class="src-sym">!</span><span class="src-sym">(</span><span class="src-id">strcasecmp</span><span class="src-sym">(</span><span class="src-var">$value</span><span class="src-sym">, </span><span class="src-str">'NULL'</span><span class="src-sym">) </span>== <span class="src-num">0</span><span class="src-sym">)) </span><span class="src-str"></span><span class="src-sym">{</span></span></li>
<li><a name="a1855"></a></span><span class="src-str">                <span class="src-var">$value</span> = <span class="src-id">str_replace</span><span class="src-sym">(</span><span class="src-str">&quot;\\\&quot;&quot;</span><span class="src-sym">,</span><span class="src-str">&quot;\&quot;&quot;</span><span class="src-sym">,</span><span class="src-var">$value</span><span class="src-sym">)</span><span class="src-sym">;</span></span></li>
<li><a name="a1856"></a></span><span class="src-str">                <span class="src-var">$value</span> = <span class="src-id">str_replace</span><span class="src-sym">(</span><span class="src-str">&quot;\'&quot;</span><span class="src-sym">,</span><span class="src-str">&quot;'&quot;</span><span class="src-sym">,</span><span class="src-var">$value</span><span class="src-sym">)</span><span class="src-sym">;</span></span></li>
<li><a name="a1857"></a></span><span class="src-str">                <span class="src-var">$value</span> = <span class="src-id">str_replace</span><span class="src-sym">(</span><span class="src-str">&quot;\\\\&quot;</span><span class="src-sym">,</span><span class="src-str">&quot;\\&quot;</span><span class="src-sym">,</span><span class="src-var">$value</span><span class="src-sym">)</span><span class="src-sym">;</span></span></li>
<li><a name="a1858"></a></span><span class="src-str">                <span class="src-var">$return</span><span class="src-sym">[</span><span class="src-var">$key</span><span class="src-sym">]</span> = <span class="src-str">&quot;'&quot;</span> . <span class="src-id">addslashes</span><span class="src-sym">(</span><span class="src-var">$value</span><span class="src-sym">)</span> . <span class="src-str">&quot;'&quot;</span><span class="src-sym">;</span></span></li>
<li><a name="a1859"></a></span><span class="src-str">            <span class="src-sym">}</span> <span class="src-key">else</span> <span class="src-sym">{</span></span></li>
<li><a name="a1860"></a></span><span class="src-str">                <span class="src-var">$return</span><span class="src-sym">[</span><span class="src-var">$key</span><span class="src-sym">]</span> = <span class="src-var">$value</span><span class="src-sym">;</span></span></li>
<li><a name="a1861"></a></span><span class="src-str">            <span class="src-sym">}</span></span></li>
<li><a name="a1862"></a></span><span class="src-str">            <span class="src-comm">//$return[$key] = $this-&gt;$db-&gt;quoteSmart($value);</span></span></li>
<li><a name="a1863"></a></span><span class="src-str"><span class="src-comm"></span>        <span class="src-sym">}</span></span></li>
<li><a name="a1864"></a></span><span class="src-str">        <span class="src-key">return</span> <span class="src-var">$return</span><span class="src-sym">;</span></span></li>
<li><a name="a1865"></a></span><span class="src-str">    <span class="src-sym">}</span></span></li>
<li><a name="a1866"></a>&nbsp;</li>
<li><a name="a1867"></a></span><span class="src-str">    /**</span></li>
<li><a name="a1868"></a></span><span class="src-str">     *  Return argument for a &quot;WHERE&quot; clause specifying this row</span></li>
<li><a name="a1869"></a></span><span class="src-str">     *</span></li>
<li><a name="a1870"></a></span><span class="src-str">     *  Returns a string which specifies the column(s) and value(s)</span></li>
<li><a name="a1871"></a></span><span class="src-str">     *  which describe the primary key of this row of the associated</span></li>
<li><a name="a1872"></a></span><span class="src-str">     *  table.  The primary key must be one or more attributes of the</span></li>
<li><a name="a1873"></a></span><span class="src-str">     *  object and must be listed in {@link $content_columns} as</span></li>
<li><a name="a1874"></a></span><span class="src-str">     *  columns in the row.</span></li>
<li><a name="a1875"></a></span><span class="src-str">     *</span></li>
<li><a name="a1876"></a></span><span class="src-str">     *  Example: if $primary_keys = array(&quot;id&quot;, &quot;ssn&quot;) and column &quot;id&quot;</span></li>
<li><a name="a1877"></a></span><span class="src-str">     *  has value &quot;5&quot; and column &quot;ssn&quot; has value &quot;123-45-6789&quot; then</span></li>
<li><a name="a1878"></a></span><span class="src-str">     *  the string &quot;id = '5' AND ssn = '123-45-6789'&quot; would be returned.</span></li>
<li><a name="a1879"></a></span><span class="src-str">     *  @uses $primary_keys</span></li>
<li><a name="a1880"></a></span><span class="src-str">     *  @uses quoted_attributes()</span></li>
<li><a name="a1881"></a></span><span class="src-str">     *  @return string Column name = 'value' [ AND name = 'value']...</span></li>
<li><a name="a1882"></a></span><span class="src-str">     */</span></li>
<li><a name="a1883"></a></span><span class="src-str">    <span class="src-key">function</span> <span class="src-id">get_primary_key_conditions</span><span class="src-sym">(</span><span class="src-sym">)</span> <span class="src-sym">{</span></span></li>
<li><a name="a1884"></a></span><span class="src-str">        <span class="src-var">$conditions</span> = <span class="src-id">null</span><span class="src-sym">;</span></span></li>
<li><a name="a1885"></a></span><span class="src-str">        <span class="src-var">$attributes</span> = <span class="src-var">$this</span></span><span class="src-sym">-&gt;</span><a href="../PHPonTrax/ActiveRecord.html#methodquoted_attributes">quoted_attributes</a><span class="src-sym">(</span><span class="src-sym">)</span><span class="src-sym">;</span></li>
<li><a name="a1886"></a>        <span class="src-key">if</span><span class="src-sym">(</span><span class="src-id">count</span><span class="src-sym">(</span><span class="src-var">$attributes</span><span class="src-sym">) </span>&gt; <span class="src-num">0</span><span class="src-sym">) </span><span class="src-str"></span><span class="src-sym">{</span></span></li>
<li><a name="a1887"></a></span><span class="src-str">            <span class="src-var">$conditions</span> = <span class="src-key">array</span><span class="src-sym">(</span><span class="src-sym">)</span><span class="src-sym">;</span></span></li>
<li><a name="a1888"></a></span><span class="src-str">            <span class="src-comm"># run through our fields and join them with their values</span></span></li>
<li><a name="a1889"></a></span><span class="src-str"><span class="src-comm"></span>            <span class="src-key">foreach</span><span class="src-sym">(</span><span class="src-var">$attributes</span> <span class="src-key">as</span> <span class="src-var">$key</span> =&gt; <span class="src-var">$value</span><span class="src-sym">)</span> <span class="src-sym">{</span></span></li>
<li><a name="a1890"></a></span><span class="src-str">                <span class="src-key">if</span><span class="src-sym">(</span><span class="src-id">in_array</span><span class="src-sym">(</span><span class="src-var">$key</span><span class="src-sym">,</span> <span class="src-var">$this</span></span><span class="src-sym">-&gt;</span><a href="../PHPonTrax/ActiveRecord.html#var$primary_keys">primary_keys</a><span class="src-sym">)) </span><span class="src-str"></span><span class="src-sym">{</span></span></li>
<li><a name="a1891"></a></span><span class="src-str">                    <span class="src-key">if</span><span class="src-sym">(</span><span class="src-sym">!</span><span class="src-id">is_numeric</span><span class="src-sym">(</span><span class="src-var">$value</span><span class="src-sym">)</span> &amp;&amp; <span class="src-sym">!</span><span class="src-id">strstr</span><span class="src-sym">(</span><span class="src-var">$value</span><span class="src-sym">,</span> <span class="src-str">&quot;'&quot;</span><span class="src-sym">))</span> <span class="src-sym">{</span></span></li>
<li><a name="a1892"></a></span><span class="src-str">                        <span class="src-var">$conditions</span><span class="src-sym">[</span><span class="src-sym">]</span> = <span class="src-str">"</span><span class="src-var">$key</span> = '<span class="src-var">$value</span>'<span class="src-str">"</span><span class="src-sym">;</span></span></li>
<li><a name="a1893"></a></span><span class="src-str">                    <span class="src-sym">}</span> <span class="src-key">else</span> <span class="src-sym">{</span></span></li>
<li><a name="a1894"></a></span><span class="src-str">                        <span class="src-var">$conditions</span><span class="src-sym">[</span><span class="src-sym">]</span> = <span class="src-str">"</span><span class="src-var">$key</span> = <span class="src-var">$value</span><span class="src-str">"</span><span class="src-sym">;</span>    </span></li>
<li><a name="a1895"></a></span><span class="src-str">                    <span class="src-sym">}</span></span></li>
<li><a name="a1896"></a></span><span class="src-str">                <span class="src-sym">}</span></span></li>
<li><a name="a1897"></a></span><span class="src-str">            <span class="src-sym">}</span></span></li>
<li><a name="a1898"></a></span><span class="src-str">            <span class="src-var">$conditions</span> = <span class="src-id">implode</span><span class="src-sym">(</span><span class="src-str">&quot; AND &quot;</span><span class="src-sym">,</span> <span class="src-var">$conditions</span><span class="src-sym">)</span><span class="src-sym">;</span></span></li>
<li><a name="a1899"></a></span><span class="src-str">        <span class="src-sym">}</span></span></li>
<li><a name="a1900"></a></span><span class="src-str">        <span class="src-key">return</span> <span class="src-var">$conditions</span><span class="src-sym">;</span></span></li>
<li><a name="a1901"></a></span><span class="src-str">    <span class="src-sym">}</span></span></li>
<li><a name="a1902"></a>&nbsp;</li>
<li><a name="a1903"></a></span><span class="src-str">    /**</span></li>
<li><a name="a1904"></a></span><span class="src-str">     *  Return column values of object formatted for SQL update statement</span></li>
<li><a name="a1905"></a></span><span class="src-str">     *</span></li>
<li><a name="a1906"></a></span><span class="src-str">     *  Return a string containing the column names and values of this</span></li>
<li><a name="a1907"></a></span><span class="src-str">     *  object in a format ready to be inserted in a SQL UPDATE</span></li>
<li><a name="a1908"></a></span><span class="src-str">     *  statement.  Automatic update has been applied to timestamps if</span></li>
<li><a name="a1909"></a></span><span class="src-str">     *  enabled and characters special to SQL have been quoted.</span></li>
<li><a name="a1910"></a></span><span class="src-str">     *  @uses quoted_attributes()</span></li>
<li><a name="a1911"></a></span><span class="src-str">     *  @return string Column name = 'value', ... for all attributes</span></li>
<li><a name="a1912"></a></span><span class="src-str">     */</span></li>
<li><a name="a1913"></a></span><span class="src-str">    <span class="src-key">function</span> <span class="src-id">get_updates_sql</span><span class="src-sym">(</span><span class="src-sym">)</span> <span class="src-sym">{</span></span></li>
<li><a name="a1914"></a></span><span class="src-str">        <span class="src-var">$updates</span> = <span class="src-id">null</span><span class="src-sym">;</span></span></li>
<li><a name="a1915"></a></span><span class="src-str">        <span class="src-var">$attributes</span> = <span class="src-var">$this</span></span><span class="src-sym">-&gt;</span><a href="../PHPonTrax/ActiveRecord.html#methodquoted_attributes">quoted_attributes</a><span class="src-sym">(</span><span class="src-sym">)</span><span class="src-sym">;</span></li>
<li><a name="a1916"></a>        <span class="src-key">if</span><span class="src-sym">(</span><span class="src-id">count</span><span class="src-sym">(</span><span class="src-var">$attributes</span><span class="src-sym">) </span>&gt; <span class="src-num">0</span><span class="src-sym">) </span><span class="src-str"></span><span class="src-sym">{</span></span></li>
<li><a name="a1917"></a></span><span class="src-str">            <span class="src-var">$updates</span> = <span class="src-key">array</span><span class="src-sym">(</span><span class="src-sym">)</span><span class="src-sym">;</span></span></li>
<li><a name="a1918"></a></span><span class="src-str">            <span class="src-comm"># run through our fields and join them with their values</span></span></li>
<li><a name="a1919"></a></span><span class="src-str"><span class="src-comm"></span>            <span class="src-key">foreach</span><span class="src-sym">(</span><span class="src-var">$attributes</span> <span class="src-key">as</span> <span class="src-var">$key</span> =&gt; <span class="src-var">$value</span><span class="src-sym">)</span> <span class="src-sym">{</span></span></li>
<li><a name="a1920"></a></span><span class="src-str">                <span class="src-key">if</span><span class="src-sym">(</span><span class="src-var">$key</span> &amp;&amp; <span class="src-var">$value</span> &amp;&amp; <span class="src-sym">!</span><span class="src-id">in_array</span><span class="src-sym">(</span><span class="src-var">$key</span><span class="src-sym">,</span> <span class="src-var">$this</span></span><span class="src-sym">-&gt;</span><a href="../PHPonTrax/ActiveRecord.html#var$primary_keys">primary_keys</a><span class="src-sym">)) </span><span class="src-str"></span><span class="src-sym">{</span></span></li>
<li><a name="a1921"></a></span><span class="src-str">                    <span class="src-var">$updates</span><span class="src-sym">[</span><span class="src-sym">]</span> = <span class="src-str">"</span><span class="src-var">$key</span> = <span class="src-var">$value</span><span class="src-str">"</span><span class="src-sym">;</span></span></li>
<li><a name="a1922"></a></span><span class="src-str">                <span class="src-sym">}</span></span></li>
<li><a name="a1923"></a></span><span class="src-str">            <span class="src-sym">}</span></span></li>
<li><a name="a1924"></a></span><span class="src-str">            <span class="src-var">$updates</span> = <span class="src-id">implode</span><span class="src-sym">(</span><span class="src-str">&quot;, &quot;</span><span class="src-sym">,</span> <span class="src-var">$updates</span><span class="src-sym">)</span><span class="src-sym">;</span></span></li>
<li><a name="a1925"></a></span><span class="src-str">        <span class="src-sym">}</span></span></li>
<li><a name="a1926"></a></span><span class="src-str">        <span class="src-key">return</span> <span class="src-var">$updates</span><span class="src-sym">;</span></span></li>
<li><a name="a1927"></a></span><span class="src-str">    <span class="src-sym">}</span></span></li>
<li><a name="a1928"></a>&nbsp;</li>
<li><a name="a1929"></a></span><span class="src-str">    /**</span></li>
<li><a name="a1930"></a></span><span class="src-str">     *  Set {@link $table_name} from the class name of this object</span></li>
<li><a name="a1931"></a></span><span class="src-str">     *</span></li>
<li><a name="a1932"></a></span><span class="src-str">     *  By convention, the name of the database table represented by</span></li>
<li><a name="a1933"></a></span><span class="src-str">     *  this object is derived from the name of the class.</span></li>
<li><a name="a1934"></a></span><span class="src-str">     *  @uses Inflector::tableize()</span></li>
<li><a name="a1935"></a></span><span class="src-str">     */</span></li>
<li><a name="a1936"></a></span><span class="src-str">    <span class="src-key">function</span> <span class="src-id">set_table_name_using_class_name</span><span class="src-sym">(</span><span class="src-sym">)</span> <span class="src-sym">{</span></span></li>
<li><a name="a1937"></a></span><span class="src-str">        <span class="src-key">if</span><span class="src-sym">(</span><span class="src-sym">!</span><span class="src-var">$this</span></span><span class="src-sym">-&gt;</span><a href="../PHPonTrax/ActiveRecord.html#var$table_name">table_name</a><span class="src-sym">) </span><span class="src-str"></span><span class="src-sym">{</span></span></li>
<li><a name="a1938"></a></span><span class="src-str">            <span class="src-var">$this</span></span><span class="src-sym">-&gt;</span><a href="../PHPonTrax/ActiveRecord.html#var$table_name">table_name</a> = <span class="src-id">Inflector</span><span class="src-sym">::</span><span class="src-id">tableize</span><span class="src-sym">(</span><span class="src-id">get_class</span><span class="src-sym">(</span><span class="src-var">$this</span><span class="src-sym">))</span><span class="src-sym">;</span></li>
<li><a name="a1939"></a>        </span><span class="src-str"><span class="src-sym">}</span></span></li>
<li><a name="a1940"></a></span><span class="src-str">    <span class="src-sym">}</span></span></li>
<li><a name="a1941"></a>&nbsp;</li>
<li><a name="a1942"></a></span><span class="src-str">    /**</span></li>
<li><a name="a1943"></a></span><span class="src-str">     *  Populate object with information about the table it represents </span></li>
<li><a name="a1944"></a></span><span class="src-str">     *</span></li>
<li><a name="a1945"></a></span><span class="src-str">     *  Call {@link </span></li>
<li><a name="a1946"></a></span><span class="src-str">     *  http://pear.php.net/manual/en/package.database.db.db-common.tableinfo.php</span></li>
<li><a name="a1947"></a></span><span class="src-str">     *  DB_common::tableInfo()} to get a description of the table and</span></li>
<li><a name="a1948"></a></span><span class="src-str">     *  store it in {@link $content_columns}.  Add a more human</span></li>
<li><a name="a1949"></a></span><span class="src-str">     *  friendly name to the element for each column.</span></li>
<li><a name="a1950"></a></span><span class="src-str">     *  &lt;b&gt;FIXME: should throw an exception if tableInfo() fails&lt;/b&gt;</span></li>
<li><a name="a1951"></a></span><span class="src-str">     *  @uses $db</span></li>
<li><a name="a1952"></a></span><span class="src-str">     *  @uses $content_columns</span></li>
<li><a name="a1953"></a></span><span class="src-str">     *  @uses Inflector::humanize()</span></li>
<li><a name="a1954"></a></span><span class="src-str">     *  @see __set()</span></li>
<li><a name="a1955"></a></span><span class="src-str">     *  @param string $table_name  Name of table to get information about</span></li>
<li><a name="a1956"></a></span><span class="src-str">     */</span></li>
<li><a name="a1957"></a></span><span class="src-str">    <span class="src-key">function</span> <span class="src-id">set_content_columns</span><span class="src-sym">(</span><span class="src-var">$table_name</span><span class="src-sym">)</span> <span class="src-sym">{</span></span></li>
<li><a name="a1958"></a></span><span class="src-str">        <span class="src-var">$this</span></span><span class="src-sym">-&gt;</span><a href="../PHPonTrax/ActiveRecord.html#var$content_columns">content_columns</a> = <span class="src-id">self</span><span class="src-sym">::</span><span class="src-var">$db</span><span class="src-sym">-&gt;</span><span class="src-id">tableInfo</span><span class="src-sym">(</span><span class="src-var">$table_name</span><span class="src-sym">)</span><span class="src-sym">;</span></li>
<li><a name="a1959"></a>        <span class="src-key">if</span><span class="src-sym">(</span><span class="src-id">is_array</span><span class="src-sym">(</span><span class="src-var">$this</span><span class="src-sym">-&gt;</span><a href="../PHPonTrax/ActiveRecord.html#var$content_columns">content_columns</a><span class="src-sym">)) </span><span class="src-str"></span><span class="src-sym">{</span></span></li>
<li><a name="a1960"></a></span><span class="src-str">            <span class="src-var">$i</span> = <span class="src-num">0</span><span class="src-sym">;</span></span></li>
<li><a name="a1961"></a></span><span class="src-str">            <span class="src-key">foreach</span><span class="src-sym">(</span><span class="src-var">$this</span></span><span class="src-sym">-&gt;</span><a href="../PHPonTrax/ActiveRecord.html#var$content_columns">content_columns</a> <span class="src-key">as </span><span class="src-var">$column</span><span class="src-sym">) </span><span class="src-str"></span><span class="src-sym">{</span></span></li>
<li><a name="a1962"></a></span><span class="src-str">                <span class="src-var">$this</span></span><span class="src-sym">-&gt;</span><a href="../PHPonTrax/ActiveRecord.html#var$content_columns">content_columns</a><span class="src-sym">[</span><span class="src-var">$i</span>++<span class="src-sym">]</span><span class="src-sym">[</span><span class="src-str">'human_name'</span><span class="src-sym">] </span>= <span class="src-id">Inflector</span><span class="src-sym">::</span><span class="src-id">humanize</span><span class="src-sym">(</span><span class="src-var">$column</span><span class="src-sym">[</span><span class="src-str">'name'</span><span class="src-sym">]</span><span class="src-sym">)</span><span class="src-sym">;</span></li>
<li><a name="a1963"></a>            </span><span class="src-str"><span class="src-sym">}</span></span></li>
<li><a name="a1964"></a></span><span class="src-str">        <span class="src-sym">}</span></span></li>
<li><a name="a1965"></a></span><span class="src-str">    <span class="src-sym">}</span></span></li>
<li><a name="a1966"></a>&nbsp;</li>
<li><a name="a1967"></a></span><span class="src-str">    /**</span></li>
<li><a name="a1968"></a></span><span class="src-str">     *  Returns the autogenerated id from the last insert query</span></li>
<li><a name="a1969"></a></span><span class="src-str">     *</span></li>
<li><a name="a1970"></a></span><span class="src-str">     *  @uses $db</span></li>
<li><a name="a1971"></a></span><span class="src-str">     *  @uses is_error()</span></li>
<li><a name="a1972"></a></span><span class="src-str">     *  @uses raise()</span></li>
<li><a name="a1973"></a></span><span class="src-str">     *  @throws {@link ActiveRecordError}</span></li>
<li><a name="a1974"></a></span><span class="src-str">     */</span></li>
<li><a name="a1975"></a></span><span class="src-str">    <span class="src-key">function</span> <span class="src-id">get_insert_id</span><span class="src-sym">(</span><span class="src-sym">)</span> <span class="src-sym">{</span></span></li>
<li><a name="a1976"></a></span><span class="src-str">        <span class="src-var">$id</span> = <span class="src-id">self</span><span class="src-sym">::</span><span class="src-var">$db</span></span><span class="src-sym">-&gt;</span><span class="src-id">getOne</span><span class="src-sym">(</span><span class="src-str">&quot;SELECT LAST_INSERT_ID();&quot;</span><span class="src-sym">)</span><span class="src-sym">;</span></li>
<li><a name="a1977"></a>        <span class="src-key">if </span><span class="src-sym">(</span><span class="src-var">$this</span><span class="src-sym">-&gt;</span><a href="../PHPonTrax/ActiveRecord.html#methodis_error">is_error</a><span class="src-sym">(</span><span class="src-var">$id</span><span class="src-sym">)) </span><span class="src-str"></span><span class="src-sym">{</span></span></li>
<li><a name="a1978"></a></span><span class="src-str">            <span class="src-var">$this</span></span><span class="src-sym">-&gt;</span><a href="../PHPonTrax/ActiveRecord.html#methodraise">raise</a><span class="src-sym">(</span><span class="src-var">$id</span><span class="src-sym">-&gt;</span><span class="src-id">getMessage</span><span class="src-sym">(</span><span class="src-sym">))</span><span class="src-sym">;</span></li>
<li><a name="a1979"></a>        </span><span class="src-str"><span class="src-sym">}</span></span></li>
<li><a name="a1980"></a></span><span class="src-str">        <span class="src-key">return</span> <span class="src-var">$id</span><span class="src-sym">;</span></span></li>
<li><a name="a1981"></a></span><span class="src-str">    <span class="src-sym">}</span></span></li>
<li><a name="a1982"></a>&nbsp;</li>
<li><a name="a1983"></a></span><span class="src-str">    /**</span></li>
<li><a name="a1984"></a></span><span class="src-str">     *  Open a database connection if one is not currently open</span></li>
<li><a name="a1985"></a></span><span class="src-str">     *</span></li>
<li><a name="a1986"></a></span><span class="src-str">     *  The name of the database normally comes from</span></li>
<li><a name="a1987"></a></span><span class="src-str">     *  $GLOBALS['TRAX_DB_SETTINGS'] which is set in {@link</span></li>
<li><a name="a1988"></a></span><span class="src-str">     *  environment.php} by reading file config/database.ini. The</span></li>
<li><a name="a1989"></a></span><span class="src-str">     *  database name may be overridden by assigning a different name</span></li>
<li><a name="a1990"></a></span><span class="src-str">     *  to {@link $database_name}. </span></li>
<li><a name="a1991"></a></span><span class="src-str">     *  </span></li>
<li><a name="a1992"></a></span><span class="src-str">     *  If there is a connection now open, as indicated by the saved</span></li>
<li><a name="a1993"></a></span><span class="src-str">     *  value of a DB object in $GLOBALS['ACTIVE_RECORD_DB'], and</span></li>
<li><a name="a1994"></a></span><span class="src-str">     *  {@link force_reconnect} is not true, then set the database</span></li>
<li><a name="a1995"></a></span><span class="src-str">     *  fetch mode and return.</span></li>
<li><a name="a1996"></a></span><span class="src-str">     *</span></li>
<li><a name="a1997"></a></span><span class="src-str">     *  If there is no connection, open one and save a reference to</span></li>
<li><a name="a1998"></a></span><span class="src-str">     *  it in $GLOBALS['ACTIVE_RECORD_DB'].</span></li>
<li><a name="a1999"></a></span><span class="src-str">     *</span></li>
<li><a name="a2000"></a></span><span class="src-str">     *  @uses $db</span></li>
<li><a name="a2001"></a></span><span class="src-str">     *  @uses $database_name</span></li>
<li><a name="a2002"></a></span><span class="src-str">     *  @uses $force_reconnect</span></li>
<li><a name="a2003"></a></span><span class="src-str">     *  @uses is_error()</span></li>
<li><a name="a2004"></a></span><span class="src-str">     *  @throws {@link ActiveRecordError}</span></li>
<li><a name="a2005"></a></span><span class="src-str">     */</span></li>
<li><a name="a2006"></a></span><span class="src-str">    <span class="src-key">function</span> <span class="src-id">establish_connection</span><span class="src-sym">(</span><span class="src-sym">)</span> <span class="src-sym">{</span></span></li>
<li><a name="a2007"></a></span><span class="src-str">        <span class="src-comm"># Connect to the database and throw an error if the connect fails.</span></span></li>
<li><a name="a2008"></a></span><span class="src-str"><span class="src-comm"></span>      <span class="src-key">if</span><span class="src-sym">(</span><span class="src-sym">!</span><span class="src-id">array_key_exists</span><span class="src-sym">(</span><span class="src-str">'ACTIVE_RECORD_DB'</span><span class="src-sym">,</span><span class="src-var">$GLOBALS</span><span class="src-sym">)</span></span></li>
<li><a name="a2009"></a></span><span class="src-str">     || <span class="src-sym">!</span><span class="src-id">is_object</span><span class="src-sym">(</span><span class="src-var">$GLOBALS</span><span class="src-sym">[</span><span class="src-str">'ACTIVE_RECORD_DB'</span><span class="src-sym">]</span><span class="src-sym">)</span></span></li>
<li><a name="a2010"></a></span><span class="src-str">     || <span class="src-var">$this</span></span><span class="src-sym">-&gt;</span><a href="../PHPonTrax/ActiveRecord.html#var$force_reconnect">force_reconnect</a><span class="src-sym">) </span><span class="src-str"></span><span class="src-sym">{</span></span></li>
<li><a name="a2011"></a></span><span class="src-str">            <span class="src-key">if</span><span class="src-sym">(</span><span class="src-id">array_key_exists</span><span class="src-sym">(</span><span class="src-str">&quot;use&quot;</span><span class="src-sym">,</span> <span class="src-var">$GLOBALS</span><span class="src-sym">[</span><span class="src-str">'TRAX_DB_SETTINGS'</span><span class="src-sym">]</span><span class="src-sym">[</span><span class="src-id">TRAX_MODE</span><span class="src-sym">]</span><span class="src-sym">))</span> <span class="src-sym">{</span></span></li>
<li><a name="a2012"></a></span><span class="src-str">                <span class="src-var">$connection_settings</span> = <span class="src-var">$GLOBALS</span><span class="src-sym">[</span><span class="src-str">'TRAX_DB_SETTINGS'</span><span class="src-sym">]</span><span class="src-sym">[</span><span class="src-var">$GLOBALS</span><span class="src-sym">[</span><span class="src-str">'TRAX_DB_SETTINGS'</span><span class="src-sym">]</span><span class="src-sym">[</span><span class="src-id">TRAX_MODE</span><span class="src-sym">]</span><span class="src-sym">[</span><span class="src-str">'use'</span><span class="src-sym">]]</span><span class="src-sym">;</span></span></li>
<li><a name="a2013"></a></span><span class="src-str">            <span class="src-sym">}</span> <span class="src-key">else</span> <span class="src-sym">{</span></span></li>
<li><a name="a2014"></a></span><span class="src-str">                <span class="src-var">$connection_settings</span> = <span class="src-var">$GLOBALS</span><span class="src-sym">[</span><span class="src-str">'TRAX_DB_SETTINGS'</span><span class="src-sym">]</span><span class="src-sym">[</span><span class="src-id">TRAX_MODE</span><span class="src-sym">]</span><span class="src-sym">;</span></span></li>
<li><a name="a2015"></a></span><span class="src-str">            <span class="src-sym">}</span></span></li>
<li><a name="a2016"></a></span><span class="src-str">            <span class="src-comm"># Override database name if param is set</span></span></li>
<li><a name="a2017"></a></span><span class="src-str"><span class="src-comm"></span>            <span class="src-key">if</span><span class="src-sym">(</span><span class="src-var">$this</span></span><span class="src-sym">-&gt;</span><a href="../PHPonTrax/ActiveRecord.html#var$database_name">database_name</a><span class="src-sym">) </span><span class="src-str"></span><span class="src-sym">{</span></span></li>
<li><a name="a2018"></a></span><span class="src-str">                <span class="src-var">$connection_settings</span><span class="src-sym">[</span><span class="src-str">'database'</span><span class="src-sym">]</span> = <span class="src-var">$this</span></span><span class="src-sym">-&gt;</span><a href="../PHPonTrax/ActiveRecord.html#var$database_name">database_name</a><span class="src-sym">;               </span></li>
<li><a name="a2019"></a>            </span><span class="src-str"><span class="src-sym">}</span>            </span></li>
<li><a name="a2020"></a></span><span class="src-str">            <span class="src-comm"># Set optional Pear parameters</span></span></li>
<li><a name="a2021"></a></span><span class="src-str"><span class="src-comm"></span>            <span class="src-key">if</span><span class="src-sym">(</span>isset<span class="src-sym">(</span><span class="src-var">$connection_settings</span><span class="src-sym">[</span><span class="src-str">'persistent'</span><span class="src-sym">]</span><span class="src-sym">))</span> <span class="src-sym">{</span></span></li>
<li><a name="a2022"></a></span><span class="src-str">                <span class="src-var">$connection_options</span><span class="src-sym">[</span><span class="src-str">'persistent'</span><span class="src-sym">]</span> =</span></li>
<li><a name="a2023"></a></span><span class="src-str">                    <span class="src-var">$connection_settings</span><span class="src-sym">[</span><span class="src-str">'persistent'</span><span class="src-sym">]</span><span class="src-sym">;</span></span></li>
<li><a name="a2024"></a></span><span class="src-str">            <span class="src-sym">}</span></span></li>
<li><a name="a2025"></a></span><span class="src-str">            <span class="src-var">$GLOBALS</span><span class="src-sym">[</span><span class="src-str">'ACTIVE_RECORD_DB'</span><span class="src-sym">]</span> =<span class="src-sym">&</span> <span class="src-id">DB</span><span class="src-sym">::</span><span class="src-id">Connect</span><span class="src-sym">(</span><span class="src-var">$connection_settings</span><span class="src-sym">,</span> <span class="src-var">$connection_options</span><span class="src-sym">)</span><span class="src-sym">;</span></span></li>
<li><a name="a2026"></a></span><span class="src-str">        <span class="src-sym">}</span></span></li>
<li><a name="a2027"></a></span><span class="src-str">        <span class="src-key">if</span><span class="src-sym">(</span><span class="src-sym">!</span><span class="src-var">$this</span></span><span class="src-sym">-&gt;</span><a href="../PHPonTrax/ActiveRecord.html#methodis_error">is_error</a><span class="src-sym">(</span><span class="src-var">$GLOBALS</span><span class="src-sym">[</span><span class="src-str">'ACTIVE_RECORD_DB'</span><span class="src-sym">]</span><span class="src-sym">)) </span><span class="src-str"></span><span class="src-sym">{</span></span></li>
<li><a name="a2028"></a></span><span class="src-str">            <span class="src-id">self</span><span class="src-sym">::</span><span class="src-var">$db</span> = <span class="src-var">$GLOBALS</span><span class="src-sym">[</span><span class="src-str">'ACTIVE_RECORD_DB'</span><span class="src-sym">]</span><span class="src-sym">;</span></span></li>
<li><a name="a2029"></a></span><span class="src-str">        <span class="src-sym">}</span> <span class="src-key">else</span> <span class="src-sym">{</span></span></li>
<li><a name="a2030"></a></span><span class="src-str">            <span class="src-var">$this</span></span><span class="src-sym">-&gt;</span><a href="../PHPonTrax/ActiveRecord.html#methodraise">raise</a><span class="src-sym">(</span><span class="src-var">$GLOBALS</span><span class="src-sym">[</span><span class="src-str">'ACTIVE_RECORD_DB'</span><span class="src-sym">]</span><span class="src-sym">-&gt;</span><span class="src-id">getMessage</span><span class="src-sym">(</span><span class="src-sym">))</span><span class="src-sym">;</span></li>
<li><a name="a2031"></a>        </span><span class="src-str"><span class="src-sym">}</span></span></li>
<li><a name="a2032"></a></span><span class="src-str">        <span class="src-id">self</span><span class="src-sym">::</span><span class="src-var">$db</span></span><span class="src-sym">-&gt;</span><span class="src-id">setFetchMode</span><span class="src-sym">(</span><span class="src-var">$this</span><span class="src-sym">-&gt;</span><a href="../PHPonTrax/ActiveRecord.html#var$fetch_mode">fetch_mode</a><span class="src-sym">)</span><span class="src-sym">;</span></li>
<li><a name="a2033"></a>        <span class="src-key">return </span><span class="src-id">self</span><span class="src-sym">::</span><span class="src-var">$db</span><span class="src-sym">;</span></li>
<li><a name="a2034"></a>    </span><span class="src-str"><span class="src-sym">}</span></span></li>
<li><a name="a2035"></a>&nbsp;</li>
<li><a name="a2036"></a></span><span class="src-str">    /**</span></li>
<li><a name="a2037"></a></span><span class="src-str">     *  Test whether argument is a PEAR Error object or a DB Error object.</span></li>
<li><a name="a2038"></a></span><span class="src-str">     *</span></li>
<li><a name="a2039"></a></span><span class="src-str">     *  @param object $obj Object to test</span></li>
<li><a name="a2040"></a></span><span class="src-str">     *  @return boolean  Whether object is one of these two errors</span></li>
<li><a name="a2041"></a></span><span class="src-str">     */</span></li>
<li><a name="a2042"></a></span><span class="src-str">    <span class="src-key">function</span> <span class="src-id">is_error</span><span class="src-sym">(</span><span class="src-var">$obj</span><span class="src-sym">)</span> <span class="src-sym">{</span></span></li>
<li><a name="a2043"></a></span><span class="src-str">        <span class="src-key">if</span><span class="src-sym">((</span><span class="src-id">PEAR</span><span class="src-sym">::</span><span class="src-id">isError</span><span class="src-sym">(</span><span class="src-var">$obj</span><span class="src-sym">))</span> || <span class="src-sym">(</span><span class="src-id">DB</span><span class="src-sym">::</span><span class="src-id">isError</span><span class="src-sym">(</span><span class="src-var">$obj</span><span class="src-sym">)))</span> <span class="src-sym">{</span></span></li>
<li><a name="a2044"></a></span><span class="src-str">            <span class="src-key">return</span> <span class="src-id">true</span><span class="src-sym">;</span></span></li>
<li><a name="a2045"></a></span><span class="src-str">        <span class="src-sym">}</span> <span class="src-key">else</span> <span class="src-sym">{</span></span></li>
<li><a name="a2046"></a></span><span class="src-str">            <span class="src-key">return</span> <span class="src-id">false</span><span class="src-sym">;</span></span></li>
<li><a name="a2047"></a></span><span class="src-str">        <span class="src-sym">}</span></span></li>
<li><a name="a2048"></a></span><span class="src-str">    <span class="src-sym">}</span></span></li>
<li><a name="a2049"></a>&nbsp;</li>
<li><a name="a2050"></a></span><span class="src-str">    /**</span></li>
<li><a name="a2051"></a></span><span class="src-str">     *  Throw an exception describing an error in this object</span></li>
<li><a name="a2052"></a></span><span class="src-str">     *</span></li>
<li><a name="a2053"></a></span><span class="src-str">     *  @throws {@link ActiveRecordError}</span></li>
<li><a name="a2054"></a></span><span class="src-str">     */</span></li>
<li><a name="a2055"></a></span><span class="src-str">    <span class="src-key">function</span> <span class="src-id">raise</span><span class="src-sym">(</span><span class="src-var">$message</span><span class="src-sym">)</span> <span class="src-sym">{</span></span></li>
<li><a name="a2056"></a></span><span class="src-str">        <span class="src-var">$error_message</span>  = <span class="src-str">&quot;Model Class: &quot;</span>.<span class="src-id">get_class</span><span class="src-sym">(</span><span class="src-var">$this</span><span class="src-sym">)</span>.<span class="src-str">&quot;&lt;br&gt;&quot;</span><span class="src-sym">;</span></span></li>
<li><a name="a2057"></a></span><span class="src-str">        <span class="src-var">$error_message</span> .= <span class="src-str">&quot;Error Message: &quot;</span>.<span class="src-var">$message</span><span class="src-sym">;</span></span></li>
<li><a name="a2058"></a></span><span class="src-str">        throw <span class="src-key">new</span> <span class="src-id">ActiveRecordError</span><span class="src-sym">(</span><span class="src-var">$error_message</span><span class="src-sym">,</span> <span class="src-str">&quot;ActiveRecord Error&quot;</span><span class="src-sym">,</span> <span class="src-str">&quot;500&quot;</span><span class="src-sym">)</span><span class="src-sym">;</span></span></li>
<li><a name="a2059"></a></span><span class="src-str">    <span class="src-sym">}</span></span></li>
<li><a name="a2060"></a>&nbsp;</li>
<li><a name="a2061"></a></span><span class="src-str">    /**</span></li>
<li><a name="a2062"></a></span><span class="src-str">     *  Add or overwrite description of an error to the list of errors</span></li>
<li><a name="a2063"></a></span><span class="src-str">     *  @param string $error Error message text</span></li>
<li><a name="a2064"></a></span><span class="src-str">     *  @param string $key Key to associate with the error (in the</span></li>
<li><a name="a2065"></a></span><span class="src-str">     *    simple case, column name).  If omitted, numeric keys will be</span></li>
<li><a name="a2066"></a></span><span class="src-str">     *    assigned starting with 0.  If specified and the key already</span></li>
<li><a name="a2067"></a></span><span class="src-str">     *    exists in $errors, the old error message will be overwritten</span></li>
<li><a name="a2068"></a></span><span class="src-str">     *    with the value of $error.</span></li>
<li><a name="a2069"></a></span><span class="src-str">     *  @uses $errors</span></li>
<li><a name="a2070"></a></span><span class="src-str">     */</span></li>
<li><a name="a2071"></a></span><span class="src-str">    <span class="src-key">function</span> <span class="src-id">add_error</span><span class="src-sym">(</span><span class="src-var">$error</span><span class="src-sym">,</span> <span class="src-var">$key</span> = <span class="src-id">null</span><span class="src-sym">)</span> <span class="src-sym">{</span></span></li>
<li><a name="a2072"></a></span><span class="src-str">        <span class="src-key">if</span><span class="src-sym">(</span><span class="src-sym">!</span><span class="src-id">is_null</span><span class="src-sym">(</span><span class="src-var">$key</span><span class="src-sym">))</span> </span></li>
<li><a name="a2073"></a></span><span class="src-str">            <span class="src-var">$this</span></span><span class="src-sym">-&gt;</span><a href="../PHPonTrax/ActiveRecord.html#var$errors">errors</a><span class="src-sym">[</span><span class="src-var">$key</span><span class="src-sym">] </span>= <span class="src-var">$error</span><span class="src-sym">;</span></li>
<li><a name="a2074"></a>        <span class="src-key">else</span></li>
<li><a name="a2075"></a>            <span class="src-var">$this</span><span class="src-sym">-&gt;</span><a href="../PHPonTrax/ActiveRecord.html#var$errors">errors</a><span class="src-sym">[</span><span class="src-sym">] </span>= <span class="src-var">$error</span><span class="src-sym">;</span></li>
<li><a name="a2076"></a>    </span><span class="src-str"><span class="src-sym">}</span></span></li>
<li><a name="a2077"></a>&nbsp;</li>
<li><a name="a2078"></a></span><span class="src-str">    /**</span></li>
<li><a name="a2079"></a></span><span class="src-str">     *  Return description of non-fatal errors</span></li>
<li><a name="a2080"></a></span><span class="src-str">     *</span></li>
<li><a name="a2081"></a></span><span class="src-str">     *  @uses $errors</span></li>
<li><a name="a2082"></a></span><span class="src-str">     *  @param boolean $return_string</span></li>
<li><a name="a2083"></a></span><span class="src-str">     *    &lt;ul&gt;</span></li>
<li><a name="a2084"></a></span><span class="src-str">     *      &lt;li&gt;true =&gt; Concatenate all error descriptions into a string</span></li>
<li><a name="a2085"></a></span><span class="src-str">     *        using $seperator between elements and return the</span></li>
<li><a name="a2086"></a></span><span class="src-str">     *        string&lt;/li&gt;</span></li>
<li><a name="a2087"></a></span><span class="src-str">     *      &lt;li&gt;false =&gt; Return the error descriptions as an array&lt;/li&gt;</span></li>
<li><a name="a2088"></a></span><span class="src-str">     *    &lt;/ul&gt;</span></li>
<li><a name="a2089"></a></span><span class="src-str">     *  @param string $seperator  String to concatenate between error</span></li>
<li><a name="a2090"></a></span><span class="src-str">     *    descriptions if $return_string == true</span></li>
<li><a name="a2091"></a></span><span class="src-str">     *  @return mixed Error description(s), if any</span></li>
<li><a name="a2092"></a></span><span class="src-str">     */</span></li>
<li><a name="a2093"></a></span><span class="src-str">    <span class="src-key">function</span> <span class="src-id">get_errors</span><span class="src-sym">(</span><span class="src-var">$return_string</span> = <span class="src-id">false</span><span class="src-sym">,</span> <span class="src-var">$seperator</span> = <span class="src-str">&quot;&lt;br&gt;&quot;</span><span class="src-sym">)</span> <span class="src-sym">{</span></span></li>
<li><a name="a2094"></a></span><span class="src-str">        <span class="src-key">if</span><span class="src-sym">(</span><span class="src-var">$return_string</span> &amp;&amp; <span class="src-id">count</span><span class="src-sym">(</span><span class="src-var">$this</span></span><span class="src-sym">-&gt;</span><a href="../PHPonTrax/ActiveRecord.html#var$errors">errors</a><span class="src-sym">) </span>&gt; <span class="src-num">0</span><span class="src-sym">) </span><span class="src-str"></span><span class="src-sym">{</span></span></li>
<li><a name="a2095"></a></span><span class="src-str">            <span class="src-key">return</span> <span class="src-id">implode</span><span class="src-sym">(</span><span class="src-var">$seperator</span><span class="src-sym">,</span> <span class="src-var">$this</span></span><span class="src-sym">-&gt;</span><a href="../PHPonTrax/ActiveRecord.html#var$errors">errors</a><span class="src-sym">)</span><span class="src-sym">;</span></li>
<li><a name="a2096"></a>        </span><span class="src-str"><span class="src-sym">}</span> <span class="src-key">else</span> <span class="src-sym">{</span></span></li>
<li><a name="a2097"></a></span><span class="src-str">            <span class="src-key">return</span> <span class="src-var">$this</span></span><span class="src-sym">-&gt;</span><a href="../PHPonTrax/ActiveRecord.html#var$errors">errors</a><span class="src-sym">;</span></li>
<li><a name="a2098"></a>        </span><span class="src-str"><span class="src-sym">}</span></span></li>
<li><a name="a2099"></a></span><span class="src-str">    <span class="src-sym">}</span></span></li>
<li><a name="a2100"></a>&nbsp;</li>
<li><a name="a2101"></a></span><span class="src-str">    /**</span></li>
<li><a name="a2102"></a></span><span class="src-str">     *  Return errors as a string.</span></li>
<li><a name="a2103"></a></span><span class="src-str">     *</span></li>
<li><a name="a2104"></a></span><span class="src-str">     *  Concatenate all error descriptions into a stringusing</span></li>
<li><a name="a2105"></a></span><span class="src-str">     *  $seperator between elements and return the string.</span></li>
<li><a name="a2106"></a></span><span class="src-str">     *  @param string $seperator  String to concatenate between error</span></li>
<li><a name="a2107"></a></span><span class="src-str">     *    descriptions</span></li>
<li><a name="a2108"></a></span><span class="src-str">     *  @return string Concatenated error description(s), if any</span></li>
<li><a name="a2109"></a></span><span class="src-str">     */</span></li>
<li><a name="a2110"></a></span><span class="src-str">    <span class="src-key">function</span> <span class="src-id">get_errors_as_string</span><span class="src-sym">(</span><span class="src-var">$seperator</span> = <span class="src-str">&quot;&lt;br&gt;&quot;</span><span class="src-sym">)</span> <span class="src-sym">{</span></span></li>
<li><a name="a2111"></a></span><span class="src-str">        <span class="src-key">return</span> <span class="src-var">$this</span></span><span class="src-sym">-&gt;</span><a href="../PHPonTrax/ActiveRecord.html#methodget_errors">get_errors</a><span class="src-sym">(</span><span class="src-id">true</span><span class="src-sym">, </span><span class="src-var">$seperator</span><span class="src-sym">)</span><span class="src-sym">;</span></li>
<li><a name="a2112"></a>    </span><span class="src-str"><span class="src-sym">}</span></span></li>
<li><a name="a2113"></a>&nbsp;</li>
<li><a name="a2114"></a></span><span class="src-str">    /**</span></li>
<li><a name="a2115"></a></span><span class="src-str">     *  Runs validation routines for update or create</span></li>
<li><a name="a2116"></a></span><span class="src-str">     *</span></li>
<li><a name="a2117"></a></span><span class="src-str">     *  @uses after_validation();</span></li>
<li><a name="a2118"></a></span><span class="src-str">     *  @uses after_validation_on_create();</span></li>
<li><a name="a2119"></a></span><span class="src-str">     *  @uses after_validation_on_update();</span></li>
<li><a name="a2120"></a></span><span class="src-str">     *  @uses before_validation();</span></li>
<li><a name="a2121"></a></span><span class="src-str">     *  @uses before_validation_on_create();</span></li>
<li><a name="a2122"></a></span><span class="src-str">     *  @uses before_validation_on_update();</span></li>
<li><a name="a2123"></a></span><span class="src-str">     *  @uses $errors</span></li>
<li><a name="a2124"></a></span><span class="src-str">     *  @uses $new_record</span></li>
<li><a name="a2125"></a></span><span class="src-str">     *  @uses validate();</span></li>
<li><a name="a2126"></a></span><span class="src-str">     *  @uses validate_model_attributes();</span></li>
<li><a name="a2127"></a></span><span class="src-str">     *  @uses validate_on_create(); </span></li>
<li><a name="a2128"></a></span><span class="src-str">     *  @return boolean </span></li>
<li><a name="a2129"></a></span><span class="src-str">     *    &lt;ul&gt;</span></li>
<li><a name="a2130"></a></span><span class="src-str">     *      &lt;li&gt;true =&gt; Valid, no errors found.</span></li>
<li><a name="a2131"></a></span><span class="src-str">     *        {@link $errors} is empty&lt;/li&gt;</span></li>
<li><a name="a2132"></a></span><span class="src-str">     *      &lt;li&gt;false =&gt; Not valid, errors in {@link $errors}&lt;/li&gt;</span></li>
<li><a name="a2133"></a></span><span class="src-str">     *    &lt;/ul&gt;</span></li>
<li><a name="a2134"></a></span><span class="src-str">     */</span></li>
<li><a name="a2135"></a></span><span class="src-str">    <span class="src-key">function</span> <span class="src-id">valid</span><span class="src-sym">(</span><span class="src-sym">)</span> <span class="src-sym">{</span></span></li>
<li><a name="a2136"></a></span><span class="src-str">        <span class="src-comm"># first clear the errors array</span></span></li>
<li><a name="a2137"></a></span><span class="src-str"><span class="src-comm"></span>        <span class="src-var">$this</span></span><span class="src-sym">-&gt;</span><a href="../PHPonTrax/ActiveRecord.html#var$errors">errors</a> = <span class="src-key">array</span><span class="src-sym">(</span><span class="src-sym">)</span><span class="src-sym">;</span></li>
<li><a name="a2138"></a>&nbsp;</li>
<li><a name="a2139"></a>        <span class="src-key">if</span><span class="src-sym">(</span><span class="src-var">$this</span><span class="src-sym">-&gt;</span><a href="../PHPonTrax/ActiveRecord.html#var$new_record">new_record</a><span class="src-sym">) </span><span class="src-str"></span><span class="src-sym">{</span></span></li>
<li><a name="a2140"></a></span><span class="src-str">            <span class="src-var">$this</span></span><span class="src-sym">-&gt;</span><a href="../PHPonTrax/ActiveRecord.html#methodbefore_validation">before_validation</a><span class="src-sym">(</span><span class="src-sym">)</span><span class="src-sym">;</span></li>
<li><a name="a2141"></a>            <span class="src-var">$this</span><span class="src-sym">-&gt;</span><a href="../PHPonTrax/ActiveRecord.html#methodbefore_validation_on_create">before_validation_on_create</a><span class="src-sym">(</span><span class="src-sym">)</span><span class="src-sym">;</span></li>
<li><a name="a2142"></a>            <span class="src-var">$this</span><span class="src-sym">-&gt;</span><a href="../PHPonTrax/ActiveRecord.html#methodvalidate">validate</a><span class="src-sym">(</span><span class="src-sym">)</span><span class="src-sym">;</span></li>
<li><a name="a2143"></a>            <span class="src-var">$this</span><span class="src-sym">-&gt;</span><a href="../PHPonTrax/ActiveRecord.html#methodvalidate_model_attributes">validate_model_attributes</a><span class="src-sym">(</span><span class="src-sym">)</span><span class="src-sym">;</span></li>
<li><a name="a2144"></a>            <span class="src-var">$this</span><span class="src-sym">-&gt;</span><a href="../PHPonTrax/ActiveRecord.html#methodafter_validation">after_validation</a><span class="src-sym">(</span><span class="src-sym">)</span><span class="src-sym">;</span></li>
<li><a name="a2145"></a>            <span class="src-var">$this</span><span class="src-sym">-&gt;</span><a href="../PHPonTrax/ActiveRecord.html#methodvalidate_on_create">validate_on_create</a><span class="src-sym">(</span><span class="src-sym">)</span><span class="src-sym">; </span></li>
<li><a name="a2146"></a>            <span class="src-var">$this</span><span class="src-sym">-&gt;</span><a href="../PHPonTrax/ActiveRecord.html#methodafter_validation_on_create">after_validation_on_create</a><span class="src-sym">(</span><span class="src-sym">)</span><span class="src-sym">;</span></li>
<li><a name="a2147"></a>        </span><span class="src-str"><span class="src-sym">}</span> <span class="src-key">else</span> <span class="src-sym">{</span></span></li>
<li><a name="a2148"></a></span><span class="src-str">            <span class="src-var">$this</span></span><span class="src-sym">-&gt;</span><a href="../PHPonTrax/ActiveRecord.html#methodbefore_validation">before_validation</a><span class="src-sym">(</span><span class="src-sym">)</span><span class="src-sym">;</span></li>
<li><a name="a2149"></a>            <span class="src-var">$this</span><span class="src-sym">-&gt;</span><a href="../PHPonTrax/ActiveRecord.html#methodbefore_validation_on_update">before_validation_on_update</a><span class="src-sym">(</span><span class="src-sym">)</span><span class="src-sym">;</span></li>
<li><a name="a2150"></a>            <span class="src-var">$this</span><span class="src-sym">-&gt;</span><a href="../PHPonTrax/ActiveRecord.html#methodvalidate">validate</a><span class="src-sym">(</span><span class="src-sym">)</span><span class="src-sym">;</span></li>
<li><a name="a2151"></a>            <span class="src-var">$this</span><span class="src-sym">-&gt;</span><a href="../PHPonTrax/ActiveRecord.html#methodvalidate_model_attributes">validate_model_attributes</a><span class="src-sym">(</span><span class="src-sym">)</span><span class="src-sym">;</span></li>
<li><a name="a2152"></a>            <span class="src-var">$this</span><span class="src-sym">-&gt;</span><a href="../PHPonTrax/ActiveRecord.html#methodafter_validation">after_validation</a><span class="src-sym">(</span><span class="src-sym">)</span><span class="src-sym">;</span></li>
<li><a name="a2153"></a>            <span class="src-var">$this</span><span class="src-sym">-&gt;</span><a href="../PHPonTrax/ActiveRecord.html#methodvalidate_on_update">validate_on_update</a><span class="src-sym">(</span><span class="src-sym">)</span><span class="src-sym">;</span></li>
<li><a name="a2154"></a>            <span class="src-var">$this</span><span class="src-sym">-&gt;</span><a href="../PHPonTrax/ActiveRecord.html#methodafter_validation_on_update">after_validation_on_update</a><span class="src-sym">(</span><span class="src-sym">)</span><span class="src-sym">;</span></li>
<li><a name="a2155"></a>        </span><span class="src-str"><span class="src-sym">}</span></span></li>
<li><a name="a2156"></a>&nbsp;</li>
<li><a name="a2157"></a></span><span class="src-str">        <span class="src-key">return</span> <span class="src-id">count</span><span class="src-sym">(</span><span class="src-var">$this</span></span><span class="src-sym">-&gt;</span><a href="../PHPonTrax/ActiveRecord.html#var$errors">errors</a><span class="src-sym">) </span>? <span class="src-id">false </span>: <span class="src-id">true</span><span class="src-sym">;</span></li>
<li><a name="a2158"></a>    </span><span class="src-str"><span class="src-sym">}</span></span></li>
<li><a name="a2159"></a>&nbsp;</li>
<li><a name="a2160"></a></span><span class="src-str">    /**</span></li>
<li><a name="a2161"></a></span><span class="src-str">     *  Call every method named &quot;validate_*()&quot; where * is a column name</span></li>
<li><a name="a2162"></a></span><span class="src-str">     *</span></li>
<li><a name="a2163"></a></span><span class="src-str">     *  Find and call every method named &quot;validate_something()&quot; where</span></li>
<li><a name="a2164"></a></span><span class="src-str">     *  &quot;something&quot; is the name of a column.  The &quot;validate_something()&quot;</span></li>
<li><a name="a2165"></a></span><span class="src-str">     *  functions are expected to return an array whose first element</span></li>
<li><a name="a2166"></a></span><span class="src-str">     *  is true or false (indicating whether or not the validation</span></li>
<li><a name="a2167"></a></span><span class="src-str">     *  succeeded), and whose second element is the error message to</span></li>
<li><a name="a2168"></a></span><span class="src-str">     *  display if the first element is false.</span></li>
<li><a name="a2169"></a></span><span class="src-str">     *</span></li>
<li><a name="a2170"></a></span><span class="src-str">     *  @return boolean </span></li>
<li><a name="a2171"></a></span><span class="src-str">     *    &lt;ul&gt;</span></li>
<li><a name="a2172"></a></span><span class="src-str">     *      &lt;li&gt;true =&gt; Valid, no errors found.</span></li>
<li><a name="a2173"></a></span><span class="src-str">     *        {@link $errors} is empty&lt;/li&gt;</span></li>
<li><a name="a2174"></a></span><span class="src-str">     *      &lt;li&gt;false =&gt; Not valid, errors in {@link $errors}.</span></li>
<li><a name="a2175"></a></span><span class="src-str">     *        $errors is an array whose keys are the names of columns,</span></li>
<li><a name="a2176"></a></span><span class="src-str">     *        and the value of each key is the error message returned</span></li>
<li><a name="a2177"></a></span><span class="src-str">     *        by the corresponding validate_*() method.&lt;/li&gt;</span></li>
<li><a name="a2178"></a></span><span class="src-str">     *    &lt;/ul&gt;</span></li>
<li><a name="a2179"></a></span><span class="src-str">     *  @uses $errors</span></li>
<li><a name="a2180"></a></span><span class="src-str">     *  @uses get_attributes()</span></li>
<li><a name="a2181"></a></span><span class="src-str">     */</span></li>
<li><a name="a2182"></a></span><span class="src-str">    <span class="src-key">function</span> <span class="src-id">validate_model_attributes</span><span class="src-sym">(</span><span class="src-sym">)</span> <span class="src-sym">{</span></span></li>
<li><a name="a2183"></a></span><span class="src-str">        <span class="src-var">$validated_ok</span> = <span class="src-id">true</span><span class="src-sym">;</span></span></li>
<li><a name="a2184"></a></span><span class="src-str">        <span class="src-var">$attrs</span> = <span class="src-var">$this</span></span><span class="src-sym">-&gt;</span><a href="../PHPonTrax/ActiveRecord.html#methodget_attributes">get_attributes</a><span class="src-sym">(</span><span class="src-sym">)</span><span class="src-sym">;</span></li>
<li><a name="a2185"></a>        <span class="src-var">$methods </span>= <span class="src-id">get_class_methods</span><span class="src-sym">(</span><span class="src-id">get_class</span><span class="src-sym">(</span><span class="src-var">$this</span><span class="src-sym">))</span><span class="src-sym">;</span></li>
<li><a name="a2186"></a>        <span class="src-key">foreach</span><span class="src-sym">(</span><span class="src-var">$methods </span><span class="src-key">as </span><span class="src-var">$method</span><span class="src-sym">) </span><span class="src-str"></span><span class="src-sym">{</span></span></li>
<li><a name="a2187"></a></span><span class="src-str">            <span class="src-key">if</span><span class="src-sym">(</span><span class="src-id">preg_match</span><span class="src-sym">(</span><span class="src-str">'/^validate_(.+)/'</span><span class="src-sym">,</span> <span class="src-var">$method</span><span class="src-sym">,</span> <span class="src-var">$matches</span><span class="src-sym">))</span> <span class="src-sym">{</span></span></li>
<li><a name="a2188"></a></span><span class="src-str">                <span class="src-comm"># If we find, for example, a method named validate_name, then</span></span></li>
<li><a name="a2189"></a></span><span class="src-str"><span class="src-comm"></span>                <span class="src-comm"># we know that that function is validating the 'name' attribute</span></span></li>
<li><a name="a2190"></a></span><span class="src-str"><span class="src-comm"></span>                <span class="src-comm"># (as found in the (.+) part of the regular expression above).</span></span></li>
<li><a name="a2191"></a></span><span class="src-str"><span class="src-comm"></span>                <span class="src-var">$validate_on_attribute</span> = <span class="src-var">$matches</span><span class="src-sym">[</span><span class="src-num">1</span><span class="src-sym">]</span><span class="src-sym">;</span></span></li>
<li><a name="a2192"></a></span><span class="src-str">                <span class="src-comm"># Check to see if the string found (e.g. 'name') really is</span></span></li>
<li><a name="a2193"></a></span><span class="src-str"><span class="src-comm"></span>                <span class="src-comm"># in the list of attributes for this object...</span></span></li>
<li><a name="a2194"></a></span><span class="src-str"><span class="src-comm"></span>                <span class="src-key">if</span><span class="src-sym">(</span><span class="src-id">array_key_exists</span><span class="src-sym">(</span><span class="src-var">$validate_on_attribute</span><span class="src-sym">,</span> <span class="src-var">$attrs</span><span class="src-sym">))</span> <span class="src-sym">{</span></span></li>
<li><a name="a2195"></a></span><span class="src-str">                    <span class="src-comm"># ...if so, then call the method to see if it validates to true...</span></span></li>
<li><a name="a2196"></a></span><span class="src-str"><span class="src-comm"></span>                    <span class="src-var">$result</span> = <span class="src-var">$this</span></span><span class="src-sym">-&gt;</span><span class="src-var">$method</span><span class="src-sym">(</span><span class="src-sym">)</span><span class="src-sym">;</span></li>
<li><a name="a2197"></a>                    <span class="src-key">if</span><span class="src-sym">(</span><span class="src-id">is_array</span><span class="src-sym">(</span><span class="src-var">$result</span><span class="src-sym">)) </span><span class="src-str"></span><span class="src-sym">{</span></span></li>
<li><a name="a2198"></a></span><span class="src-str">                        <span class="src-comm"># $result[0] is true if validation went ok, false otherwise</span></span></li>
<li><a name="a2199"></a></span><span class="src-str"><span class="src-comm"></span>                        <span class="src-comm"># $result[1] is the error message if validation failed</span></span></li>
<li><a name="a2200"></a></span><span class="src-str"><span class="src-comm"></span>                        <span class="src-key">if</span><span class="src-sym">(</span><span class="src-var">$result</span><span class="src-sym">[</span><span class="src-num">0</span><span class="src-sym">]</span> == <span class="src-id">false</span><span class="src-sym">)</span> <span class="src-sym">{</span></span></li>
<li><a name="a2201"></a></span><span class="src-str">                            <span class="src-comm"># ... and if not, then validation failed</span></span></li>
<li><a name="a2202"></a></span><span class="src-str"><span class="src-comm"></span>                            <span class="src-var">$validated_ok</span> = <span class="src-id">false</span><span class="src-sym">;</span></span></li>
<li><a name="a2203"></a></span><span class="src-str">                            <span class="src-comm"># Mark the corresponding entry in the error array by</span></span></li>
<li><a name="a2204"></a></span><span class="src-str"><span class="src-comm"></span>                            <span class="src-comm"># putting the error message in for the attribute,</span></span></li>
<li><a name="a2205"></a></span><span class="src-str"><span class="src-comm"></span>                            <span class="src-comm">#   e.g. $this-&gt;errors['name'] = &quot;can't be empty&quot;</span></span></li>
<li><a name="a2206"></a></span><span class="src-str"><span class="src-comm"></span>                            <span class="src-comm">#   when 'name' was an empty string.</span></span></li>
<li><a name="a2207"></a></span><span class="src-str"><span class="src-comm"></span>                            <span class="src-var">$this</span></span><span class="src-sym">-&gt;</span><a href="../PHPonTrax/ActiveRecord.html#var$errors">errors</a><span class="src-sym">[</span><span class="src-var">$validate_on_attribute</span><span class="src-sym">] </span>= <span class="src-var">$result</span><span class="src-sym">[</span><span class="src-num">1</span><span class="src-sym">]</span><span class="src-sym">;</span></li>
<li><a name="a2208"></a>                        </span><span class="src-str"><span class="src-sym">}</span></span></li>
<li><a name="a2209"></a></span><span class="src-str">                    <span class="src-sym">}</span></span></li>
<li><a name="a2210"></a></span><span class="src-str">                <span class="src-sym">}</span></span></li>
<li><a name="a2211"></a></span><span class="src-str">            <span class="src-sym">}</span></span></li>
<li><a name="a2212"></a></span><span class="src-str">        <span class="src-sym">}</span></span></li>
<li><a name="a2213"></a></span><span class="src-str">        <span class="src-key">return</span> <span class="src-var">$validated_ok</span><span class="src-sym">;</span></span></li>
<li><a name="a2214"></a></span><span class="src-str">    <span class="src-sym">}</span></span></li>
<li><a name="a2215"></a>&nbsp;</li>
<li><a name="a2216"></a></span><span class="src-str">    /**</span></li>
<li><a name="a2217"></a></span><span class="src-str">     *  Overwrite this method for validation checks on all saves and</span></li>
<li><a name="a2218"></a></span><span class="src-str">     *  use $this-&gt;errors[] = &quot;My error message.&quot;; or</span></li>
<li><a name="a2219"></a></span><span class="src-str">     *  for invalid attributes $this-&gt;errors['attribute'] = &quot;Attribute is invalid.&quot;;</span></li>
<li><a name="a2220"></a></span><span class="src-str">     *  @todo Document this API</span></li>
<li><a name="a2221"></a></span><span class="src-str">     */</span></li>
<li><a name="a2222"></a></span><span class="src-str">    <span class="src-key">function</span> <span class="src-id">validate</span><span class="src-sym">(</span><span class="src-sym">)</span> <span class="src-sym">{</span><span class="src-sym">}</span></span></li>
<li><a name="a2223"></a>&nbsp;</li>
<li><a name="a2224"></a></span><span class="src-str">    /**</span></li>
<li><a name="a2225"></a></span><span class="src-str">     *  Override this method for validation checks used only on creation.</span></li>
<li><a name="a2226"></a></span><span class="src-str">     *  @todo Document this API</span></li>
<li><a name="a2227"></a></span><span class="src-str">     */</span></li>
<li><a name="a2228"></a></span><span class="src-str">    <span class="src-key">function</span> <span class="src-id">validate_on_create</span><span class="src-sym">(</span><span class="src-sym">)</span> <span class="src-sym">{</span><span class="src-sym">}</span></span></li>
<li><a name="a2229"></a>&nbsp;</li>
<li><a name="a2230"></a></span><span class="src-str">    /**</span></li>
<li><a name="a2231"></a></span><span class="src-str">     *  Override this method for validation checks used only on updates.</span></li>
<li><a name="a2232"></a></span><span class="src-str">     *  @todo Document this API</span></li>
<li><a name="a2233"></a></span><span class="src-str">     */</span></li>
<li><a name="a2234"></a></span><span class="src-str">    <span class="src-key">function</span> <span class="src-id">validate_on_update</span><span class="src-sym">(</span><span class="src-sym">)</span> <span class="src-sym">{</span><span class="src-sym">}</span></span></li>
<li><a name="a2235"></a>&nbsp;</li>
<li><a name="a2236"></a></span><span class="src-str">    /**</span></li>
<li><a name="a2237"></a></span><span class="src-str">     *  Is called before validate().</span></li>
<li><a name="a2238"></a></span><span class="src-str">     *  @todo Document this API</span></li>
<li><a name="a2239"></a></span><span class="src-str">     */</span></li>
<li><a name="a2240"></a></span><span class="src-str">    <span class="src-key">function</span> <span class="src-id">before_validation</span><span class="src-sym">(</span><span class="src-sym">)</span> <span class="src-sym">{</span><span class="src-sym">}</span></span></li>
<li><a name="a2241"></a>&nbsp;</li>
<li><a name="a2242"></a></span><span class="src-str">    /**</span></li>
<li><a name="a2243"></a></span><span class="src-str">     *  Is called after validate().</span></li>
<li><a name="a2244"></a></span><span class="src-str">     *  @todo Document this API</span></li>
<li><a name="a2245"></a></span><span class="src-str">     */</span></li>
<li><a name="a2246"></a></span><span class="src-str">    <span class="src-key">function</span> <span class="src-id">after_validation</span><span class="src-sym">(</span><span class="src-sym">)</span> <span class="src-sym">{</span><span class="src-sym">}</span></span></li>
<li><a name="a2247"></a>&nbsp;</li>
<li><a name="a2248"></a></span><span class="src-str">    /**</span></li>
<li><a name="a2249"></a></span><span class="src-str">     *  Is called before validate() on new objects that haven't been saved yet (no record exists).</span></li>
<li><a name="a2250"></a></span><span class="src-str">     *  @todo Document this API</span></li>
<li><a name="a2251"></a></span><span class="src-str">     */</span></li>
<li><a name="a2252"></a></span><span class="src-str">    <span class="src-key">function</span> <span class="src-id">before_validation_on_create</span><span class="src-sym">(</span><span class="src-sym">)</span> <span class="src-sym">{</span><span class="src-sym">}</span></span></li>
<li><a name="a2253"></a>&nbsp;</li>
<li><a name="a2254"></a></span><span class="src-str">    /**</span></li>
<li><a name="a2255"></a></span><span class="src-str">     *  Is called after validate() on new objects that haven't been saved yet (no record exists).</span></li>
<li><a name="a2256"></a></span><span class="src-str">     *  @todo Document this API</span></li>
<li><a name="a2257"></a></span><span class="src-str">     */</span></li>
<li><a name="a2258"></a></span><span class="src-str">    <span class="src-key">function</span> <span class="src-id">after_validation_on_create</span><span class="src-sym">(</span><span class="src-sym">)</span>  <span class="src-sym">{</span><span class="src-sym">}</span></span></li>
<li><a name="a2259"></a>&nbsp;</li>
<li><a name="a2260"></a></span><span class="src-str">    /**</span></li>
<li><a name="a2261"></a></span><span class="src-str">     *  Is called before validate() on existing objects that has a record.</span></li>
<li><a name="a2262"></a></span><span class="src-str">     *  @todo Document this API</span></li>
<li><a name="a2263"></a></span><span class="src-str">     */</span></li>
<li><a name="a2264"></a></span><span class="src-str">    <span class="src-key">function</span> <span class="src-id">before_validation_on_update</span><span class="src-sym">(</span><span class="src-sym">)</span> <span class="src-sym">{</span><span class="src-sym">}</span></span></li>
<li><a name="a2265"></a>&nbsp;</li>
<li><a name="a2266"></a></span><span class="src-str">    /**</span></li>
<li><a name="a2267"></a></span><span class="src-str">     *  Is called after validate() on existing objects that has a record.</span></li>
<li><a name="a2268"></a></span><span class="src-str">     *  @todo Document this API</span></li>
<li><a name="a2269"></a></span><span class="src-str">     */</span></li>
<li><a name="a2270"></a></span><span class="src-str">    <span class="src-key">function</span> <span class="src-id">after_validation_on_update</span><span class="src-sym">(</span><span class="src-sym">)</span>  <span class="src-sym">{</span><span class="src-sym">}</span></span></li>
<li><a name="a2271"></a>&nbsp;</li>
<li><a name="a2272"></a></span><span class="src-str">    /**</span></li>
<li><a name="a2273"></a></span><span class="src-str">     *  Is called before save() (regardless of whether its a create or update save)</span></li>
<li><a name="a2274"></a></span><span class="src-str">     *  @todo Document this API</span></li>
<li><a name="a2275"></a></span><span class="src-str">     */</span></li>
<li><a name="a2276"></a></span><span class="src-str">    <span class="src-key">function</span> <span class="src-id">before_save</span><span class="src-sym">(</span><span class="src-sym">)</span> <span class="src-sym">{</span><span class="src-sym">}</span></span></li>
<li><a name="a2277"></a>&nbsp;</li>
<li><a name="a2278"></a></span><span class="src-str">    /**</span></li>
<li><a name="a2279"></a></span><span class="src-str">     *  Is called after save (regardless of whether its a create or update save).</span></li>
<li><a name="a2280"></a></span><span class="src-str">     *  @todo Document this API</span></li>
<li><a name="a2281"></a></span><span class="src-str">     */</span></li>
<li><a name="a2282"></a></span><span class="src-str">    <span class="src-key">function</span> <span class="src-id">after_save</span><span class="src-sym">(</span><span class="src-sym">)</span> <span class="src-sym">{</span><span class="src-sym">}</span></span></li>
<li><a name="a2283"></a>&nbsp;</li>
<li><a name="a2284"></a></span><span class="src-str">    /**</span></li>
<li><a name="a2285"></a></span><span class="src-str">     *  Is called before save() on new objects that havent been saved yet (no record exists).</span></li>
<li><a name="a2286"></a></span><span class="src-str">     *  @todo Document this API</span></li>
<li><a name="a2287"></a></span><span class="src-str">     */</span></li>
<li><a name="a2288"></a></span><span class="src-str">    <span class="src-key">function</span> <span class="src-id">before_create</span><span class="src-sym">(</span><span class="src-sym">)</span> <span class="src-sym">{</span><span class="src-sym">}</span></span></li>
<li><a name="a2289"></a>&nbsp;</li>
<li><a name="a2290"></a></span><span class="src-str">    /**</span></li>
<li><a name="a2291"></a></span><span class="src-str">     *  Is called after save() on new objects that havent been saved yet (no record exists).</span></li>
<li><a name="a2292"></a></span><span class="src-str">     *  @todo Document this API</span></li>
<li><a name="a2293"></a></span><span class="src-str">     */</span></li>
<li><a name="a2294"></a></span><span class="src-str">    <span class="src-key">function</span> <span class="src-id">after_create</span><span class="src-sym">(</span><span class="src-sym">)</span> <span class="src-sym">{</span><span class="src-sym">}</span></span></li>
<li><a name="a2295"></a>&nbsp;</li>
<li><a name="a2296"></a></span><span class="src-str">    /**</span></li>
<li><a name="a2297"></a></span><span class="src-str">     *  Is called before save() on existing objects that has a record.</span></li>
<li><a name="a2298"></a></span><span class="src-str">     *  @todo Document this API</span></li>
<li><a name="a2299"></a></span><span class="src-str">     */</span></li>
<li><a name="a2300"></a></span><span class="src-str">    <span class="src-key">function</span> <span class="src-id">before_update</span><span class="src-sym">(</span><span class="src-sym">)</span> <span class="src-sym">{</span><span class="src-sym">}</span></span></li>
<li><a name="a2301"></a>&nbsp;</li>
<li><a name="a2302"></a></span><span class="src-str">    /**</span></li>
<li><a name="a2303"></a></span><span class="src-str">     *  Is called after save() on existing objects that has a record.</span></li>
<li><a name="a2304"></a></span><span class="src-str">     *  @todo Document this API</span></li>
<li><a name="a2305"></a></span><span class="src-str">     */</span></li>
<li><a name="a2306"></a></span><span class="src-str">    <span class="src-key">function</span> <span class="src-id">after_update</span><span class="src-sym">(</span><span class="src-sym">)</span> <span class="src-sym">{</span><span class="src-sym">}</span></span></li>
<li><a name="a2307"></a>&nbsp;</li>
<li><a name="a2308"></a></span><span class="src-str">    /**</span></li>
<li><a name="a2309"></a></span><span class="src-str">     *  Is called before delete().</span></li>
<li><a name="a2310"></a></span><span class="src-str">     *  @todo Document this API</span></li>
<li><a name="a2311"></a></span><span class="src-str">     */</span></li>
<li><a name="a2312"></a></span><span class="src-str">    <span class="src-key">function</span> <span class="src-id">before_delete</span><span class="src-sym">(</span><span class="src-sym">)</span> <span class="src-sym">{</span><span class="src-sym">}</span></span></li>
<li><a name="a2313"></a>&nbsp;</li>
<li><a name="a2314"></a></span><span class="src-str">    /**</span></li>
<li><a name="a2315"></a></span><span class="src-str">     *  Is called after delete().</span></li>
<li><a name="a2316"></a></span><span class="src-str">     *  @todo Document this API</span></li>
<li><a name="a2317"></a></span><span class="src-str">     */</span></li>
<li><a name="a2318"></a></span><span class="src-str">    <span class="src-key">function</span> <span class="src-id">after_delete</span><span class="src-sym">(</span><span class="src-sym">)</span> <span class="src-sym">{</span><span class="src-sym">}</span></span></li>
<li><a name="a2319"></a>&nbsp;</li>
<li><a name="a2320"></a></span><span class="src-str">    /**</span></li>
<li><a name="a2321"></a></span><span class="src-str">     *  Log SQL query in development mode</span></li>
<li><a name="a2322"></a></span><span class="src-str">     *</span></li>
<li><a name="a2323"></a></span><span class="src-str">     *  If running in development mode, log the query to $GLOBAL</span></li>
<li><a name="a2324"></a></span><span class="src-str">     *  @param string SQL to be logged</span></li>
<li><a name="a2325"></a></span><span class="src-str">     */</span></li>
<li><a name="a2326"></a></span><span class="src-str">    <span class="src-key">function</span> <span class="src-id">log_query</span><span class="src-sym">(</span><span class="src-var">$sql</span><span class="src-sym">)</span> <span class="src-sym">{</span></span></li>
<li><a name="a2327"></a></span><span class="src-str">        <span class="src-key">if</span><span class="src-sym">(</span><span class="src-id">TRAX_MODE</span> == <span class="src-str">&quot;development&quot;</span> &amp;&amp; <span class="src-var">$sql</span><span class="src-sym">)</span> <span class="src-sym">{</span></span></li>
<li><a name="a2328"></a></span><span class="src-str">            <span class="src-var">$GLOBALS</span><span class="src-sym">[</span><span class="src-str">'ACTIVE_RECORD_SQL_LOG'</span><span class="src-sym">]</span><span class="src-sym">[</span><span class="src-sym">]</span> = <span class="src-var">$sql</span><span class="src-sym">;</span>       </span></li>
<li><a name="a2329"></a></span><span class="src-str">        <span class="src-sym">}</span>    </span></li>
<li><a name="a2330"></a></span><span class="src-str">    <span class="src-sym">}</span></span></li>
<li><a name="a2331"></a>&nbsp;</li>
<li><a name="a2332"></a></span><span class="src-str">    /**</span></li>
<li><a name="a2333"></a></span><span class="src-str">     * Paging html functions</span></li>
<li><a name="a2334"></a></span><span class="src-str">     *  @todo Document this API</span></li>
<li><a name="a2335"></a></span><span class="src-str">     */</span></li>
<li><a name="a2336"></a></span><span class="src-str">    <span class="src-key">function</span> <span class="src-id">limit_select</span><span class="src-sym">(</span><span class="src-var">$controller</span> =<span class="src-id">null</span><span class="src-sym">,</span> <span class="src-var">$additional_query</span> = <span class="src-id">null</span><span class="src-sym">)</span> <span class="src-sym">{</span></span></li>
<li><a name="a2337"></a></span><span class="src-str">        <span class="src-key">if</span><span class="src-sym">(</span><span class="src-var">$this</span></span><span class="src-sym">-&gt;</span><span class="src-var">pages </span>&gt; <span class="src-num">0</span><span class="src-sym">) </span><span class="src-str"></span><span class="src-sym">{</span></span></li>
<li><a name="a2338"></a></span><span class="src-str">            <span class="src-var">$html</span> = <span class="src-str">"</span></span></li>
<li><a name="a2339"></a></span><span class="src-str">                &lt;<span class="src-id">select</span> <span class="src-id">name</span>=\&quot;<span class="src-id">per_page</span>\&quot; <span class="src-id">onChange</span>=\&quot;<span class="src-id">document</span>.<span class="src-id">location</span> = '?<span class="src-var">$this</span></span><span class="src-sym">-&gt;</span><span class="src-var">paging_extra_params</span>&amp;<span class="src-id">per_page</span>=' + <span class="src-id">this</span>.<span class="src-id">options</span><span class="src-sym">[</span><span class="src-id">this</span>.<span class="src-id">selectedIndex</span><span class="src-sym">]</span>.<span class="src-id">value</span>;\&quot;&gt;</li>
<li><a name="a2340"></a>                    &lt;<span class="src-id">option value</span>=\&quot;<span class="src-var">$this</span><span class="src-sym">-&gt;</span><span class="src-var">rows_per_page</span>\&quot; <span class="src-id">selected</span>&gt;<span class="src-id">per page</span>:&lt;/<span class="src-id">option</span>&gt;</li>
<li><a name="a2341"></a>                    &lt;<span class="src-id">option value</span>=10&gt;10&lt;/<span class="src-id">option</span>&gt;</li>
<li><a name="a2342"></a>                    &lt;<span class="src-id">option value</span>=20&gt;20&lt;/<span class="src-id">option</span>&gt;</li>
<li><a name="a2343"></a>                    &lt;<span class="src-id">option value</span>=50&gt;50&lt;/<span class="src-id">option</span>&gt;</li>
<li><a name="a2344"></a>                    &lt;<span class="src-id">option value</span>=100&gt;100&lt;/<span class="src-id">option</span>&gt;</li>
<li><a name="a2345"></a>                    &lt;<span class="src-id">option value</span>=999999999&gt;<span class="src-id">ALL</span>&lt;/<span class="src-id">option</span>&gt;</li>
<li><a name="a2346"></a>                &lt;/<span class="src-id">select</span>&gt;</li>
<li><a name="a2347"></a>            </span><span class="src-str"><span class="src-str">"</span><span class="src-sym">;</span></span></li>
<li><a name="a2348"></a></span><span class="src-str">        <span class="src-sym">}</span></span></li>
<li><a name="a2349"></a></span><span class="src-str">        <span class="src-key">return</span> <span class="src-var">$html</span><span class="src-sym">;</span></span></li>
<li><a name="a2350"></a></span><span class="src-str">    <span class="src-sym">}</span></span></li>
<li><a name="a2351"></a>&nbsp;</li>
<li><a name="a2352"></a></span><span class="src-str">    /**</span></li>
<li><a name="a2353"></a></span><span class="src-str">     *  @todo Document this API</span></li>
<li><a name="a2354"></a></span><span class="src-str">     *</span></li>
<li><a name="a2355"></a></span><span class="src-str">     *  @return string HTML to link to previous and next pages</span></li>
<li><a name="a2356"></a></span><span class="src-str">     *  @uses $display</span></li>
<li><a name="a2357"></a></span><span class="src-str">     *  @uses $page</span></li>
<li><a name="a2358"></a></span><span class="src-str">     *  @uses $pages</span></li>
<li><a name="a2359"></a></span><span class="src-str">     *  @uses $paging_extra_params</span></li>
<li><a name="a2360"></a></span><span class="src-str">     *  @uses rows_per_page</span></li>
<li><a name="a2361"></a></span><span class="src-str">     */</span></li>
<li><a name="a2362"></a></span><span class="src-str">    <span class="src-key">function</span> <span class="src-id">page_list</span><span class="src-sym">(</span><span class="src-sym">)</span><span class="src-sym">{</span></span></li>
<li><a name="a2363"></a></span><span class="src-str">        <span class="src-var">$page_list</span>  = <span class="src-str">&quot;&quot;</span><span class="src-sym">;</span></span></li>
<li><a name="a2364"></a>&nbsp;</li>
<li><a name="a2365"></a></span><span class="src-str">        <span class="src-comm">/* Print the first and previous page links if necessary */</span></span></li>
<li><a name="a2366"></a></span><span class="src-str">        <span class="src-key">if</span><span class="src-sym">((</span><span class="src-var">$this</span></span><span class="src-sym">-&gt;</span><span class="src-var">page </span>!= <span class="src-num">1</span><span class="src-sym">) </span>&amp;&amp; <span class="src-sym">(</span><span class="src-var">$this</span><span class="src-sym">-&gt;</span><span class="src-var">page</span><span class="src-sym">))</span></li>
<li><a name="a2367"></a>            <span class="src-var">$page_list </span>.= </span><span class="src-str"><span class="src-str">"</span>&lt;<span class="src-id">a</span> <span class="src-id">href</span>=\&quot;?<span class="src-var">$this</span></span><span class="src-sym">-&gt;</span><span class="src-var">paging_extra_params</span>&amp;<span class="src-id">page</span>=1&amp;<span class="src-id">per_page</span>=<span class="src-var">$this</span><span class="src-sym">-&gt;</span><span class="src-var">rows_per_page</span>\&quot; <span class="src-id">class</span>=\&quot;<span class="src-id">page_list</span>\&quot; <span class="src-id">title</span>=\&quot;<span class="src-id">First Page</span>\&quot;&gt;&lt;&lt;&lt;/<span class="src-id">a</span>&gt; </span><span class="src-str"><span class="src-str">"</span><span class="src-sym">;</span></span></li>
<li><a name="a2368"></a>&nbsp;</li>
<li><a name="a2369"></a></span><span class="src-str">        <span class="src-key">if</span><span class="src-sym">((</span><span class="src-var">$this</span></span><span class="src-sym">-&gt;</span><span class="src-var">page</span>-<span class="src-num">1</span><span class="src-sym">) </span>&gt; <span class="src-num">0</span><span class="src-sym">)</span></li>
<li><a name="a2370"></a>            <span class="src-var">$page_list </span>.= </span><span class="src-str"><span class="src-str">"</span>&lt;<span class="src-id">a</span> <span class="src-id">href</span>=\&quot;?<span class="src-var">$this</span></span><span class="src-sym">-&gt;</span><span class="src-var">paging_extra_params</span>&amp;<span class="src-id">page</span>=</span><span class="src-str"><span class="src-str">"</span>.<span class="src-sym">(</span><span class="src-var">$this</span></span><span class="src-sym">-&gt;</span><span class="src-var">page</span>-<span class="src-num">1</span><span class="src-sym">)</span>.</span><span class="src-str"><span class="src-str">"</span>&amp;<span class="src-id">per_page</span>=<span class="src-var">$this</span></span><span class="src-sym">-&gt;</span><span class="src-var">rows_per_page</span>\&quot; <span class="src-id">class</span>=\&quot;<span class="src-id">page_list</span>\&quot; <span class="src-id">title</span>=\&quot;<span class="src-id">Previous Page</span>\&quot;&gt;&lt;&lt;/<span class="src-id">a</span>&gt; </span><span class="src-str"><span class="src-str">"</span><span class="src-sym">;</span></span></li>
<li><a name="a2371"></a>&nbsp;</li>
<li><a name="a2372"></a></span><span class="src-str">        <span class="src-key">if</span><span class="src-sym">(</span><span class="src-var">$this</span></span><span class="src-sym">-&gt;</span><span class="src-var">pages </span>&lt; <span class="src-var">$this</span><span class="src-sym">-&gt;</span><a href="../PHPonTrax/ActiveRecord.html#var$display">display</a><span class="src-sym">)</span></li>
<li><a name="a2373"></a>            <span class="src-var">$this</span><span class="src-sym">-&gt;</span><a href="../PHPonTrax/ActiveRecord.html#var$display">display</a> = <span class="src-var">$this</span><span class="src-sym">-&gt;</span><span class="src-var">pages</span><span class="src-sym">;</span></li>
<li><a name="a2374"></a>&nbsp;</li>
<li><a name="a2375"></a>        <span class="src-key">if</span><span class="src-sym">(</span><span class="src-var">$this</span><span class="src-sym">-&gt;</span><span class="src-var">page </span>== <span class="src-var">$this</span><span class="src-sym">-&gt;</span><span class="src-var">pages</span><span class="src-sym">) </span><span class="src-str"></span><span class="src-sym">{</span></span></li>
<li><a name="a2376"></a></span><span class="src-str">            <span class="src-key">if</span><span class="src-sym">(</span><span class="src-var">$this</span></span><span class="src-sym">-&gt;</span><span class="src-var">pages </span>- <span class="src-var">$this</span><span class="src-sym">-&gt;</span><a href="../PHPonTrax/ActiveRecord.html#var$display">display</a> == <span class="src-num">0</span><span class="src-sym">)</span></li>
<li><a name="a2377"></a>                <span class="src-var">$start </span>= <span class="src-num">1</span><span class="src-sym">;</span></li>
<li><a name="a2378"></a>            <span class="src-key">else</span></li>
<li><a name="a2379"></a>                <span class="src-var">$start </span>= <span class="src-var">$this</span><span class="src-sym">-&gt;</span><span class="src-var">pages </span>- <span class="src-var">$this</span><span class="src-sym">-&gt;</span><a href="../PHPonTrax/ActiveRecord.html#var$display">display</a><span class="src-sym">;</span></li>
<li><a name="a2380"></a>            <span class="src-var">$max </span>= <span class="src-var">$this</span><span class="src-sym">-&gt;</span><span class="src-var">pages</span><span class="src-sym">;</span></li>
<li><a name="a2381"></a>        </span><span class="src-str"><span class="src-sym">}</span> <span class="src-key">else</span> <span class="src-sym">{</span></span></li>
<li><a name="a2382"></a></span><span class="src-str">            <span class="src-key">if</span><span class="src-sym">(</span><span class="src-var">$this</span></span><span class="src-sym">-&gt;</span><span class="src-var">page </span>&gt;= <span class="src-var">$this</span><span class="src-sym">-&gt;</span><a href="../PHPonTrax/ActiveRecord.html#var$display">display</a><span class="src-sym">) </span><span class="src-str"></span><span class="src-sym">{</span></span></li>
<li><a name="a2383"></a></span><span class="src-str">                <span class="src-var">$start</span> = <span class="src-var">$this</span></span><span class="src-sym">-&gt;</span><span class="src-var">page </span>- <span class="src-sym">(</span><span class="src-var">$this</span><span class="src-sym">-&gt;</span><a href="../PHPonTrax/ActiveRecord.html#var$display">display</a> / <span class="src-num">2</span><span class="src-sym">)</span><span class="src-sym">;</span></li>
<li><a name="a2384"></a>                <span class="src-var">$max   </span>= <span class="src-var">$this</span><span class="src-sym">-&gt;</span><span class="src-var">page </span>+ <span class="src-sym">((</span><span class="src-var">$this</span><span class="src-sym">-&gt;</span><a href="../PHPonTrax/ActiveRecord.html#var$display">display</a> / <span class="src-num">2</span><span class="src-sym">)</span>-<span class="src-num">1</span><span class="src-sym">)</span><span class="src-sym">;</span></li>
<li><a name="a2385"></a>            </span><span class="src-str"><span class="src-sym">}</span> <span class="src-key">else</span> <span class="src-sym">{</span></span></li>
<li><a name="a2386"></a></span><span class="src-str">                <span class="src-var">$start</span> = <span class="src-num">1</span><span class="src-sym">;</span></span></li>
<li><a name="a2387"></a></span><span class="src-str">                <span class="src-var">$max</span>   = <span class="src-var">$this</span></span><span class="src-sym">-&gt;</span><a href="../PHPonTrax/ActiveRecord.html#var$display">display</a><span class="src-sym">;</span></li>
<li><a name="a2388"></a>            </span><span class="src-str"><span class="src-sym">}</span></span></li>
<li><a name="a2389"></a></span><span class="src-str">        <span class="src-sym">}</span></span></li>
<li><a name="a2390"></a>&nbsp;</li>
<li><a name="a2391"></a></span><span class="src-str">        <span class="src-key">if</span><span class="src-sym">(</span><span class="src-var">$max</span> &gt;= <span class="src-var">$this</span></span><span class="src-sym">-&gt;</span><span class="src-var">pages</span><span class="src-sym">)</span></li>
<li><a name="a2392"></a>            <span class="src-var">$max </span>= <span class="src-var">$this</span><span class="src-sym">-&gt;</span><span class="src-var">pages</span><span class="src-sym">;</span></li>
<li><a name="a2393"></a>&nbsp;</li>
<li><a name="a2394"></a>        <span class="src-comm">/* Print the numeric page list; make the current page unlinked and bold */</span></li>
<li><a name="a2395"></a>        <span class="src-key">if</span><span class="src-sym">(</span><span class="src-var">$max </span>!= <span class="src-num">1</span><span class="src-sym">) </span><span class="src-str"></span><span class="src-sym">{</span></span></li>
<li><a name="a2396"></a></span><span class="src-str">            <span class="src-key">for</span> <span class="src-sym">(</span><span class="src-var">$i</span>=<span class="src-var">$start</span><span class="src-sym">;</span> <span class="src-var">$i</span>&lt;=<span class="src-var">$max</span><span class="src-sym">;</span> <span class="src-var">$i</span>++<span class="src-sym">)</span> <span class="src-sym">{</span></span></li>
<li><a name="a2397"></a></span><span class="src-str">                <span class="src-key">if</span> <span class="src-sym">(</span><span class="src-var">$i</span> == <span class="src-var">$this</span></span><span class="src-sym">-&gt;</span><span class="src-var">page</span><span class="src-sym">)</span></li>
<li><a name="a2398"></a>                    <span class="src-var">$page_list </span>.= <span class="src-str">&quot;&lt;span class=\&quot;pageList\&quot;&gt;&lt;b&gt;&quot;</span>.<span class="src-var">$i</span>.<span class="src-str">&quot;&lt;/b&gt;&lt;/span&gt;&quot;</span><span class="src-sym">;</span></li>
<li><a name="a2399"></a>                <span class="src-key">else</span></li>
<li><a name="a2400"></a>                    <span class="src-var">$page_list </span>.= </span><span class="src-str"><span class="src-str">"</span>&lt;<span class="src-id">a</span> <span class="src-id">href</span>=\&quot;?<span class="src-var">$this</span></span><span class="src-sym">-&gt;</span><span class="src-var">paging_extra_params</span>&amp;<span class="src-id">page</span>=<span class="src-var">$i</span>&amp;<span class="src-id">per_page</span>=<span class="src-var">$this</span><span class="src-sym">-&gt;</span><span class="src-var">rows_per_page</span>\&quot; <span class="src-id">class</span>=\&quot;<span class="src-id">page_list</span>\&quot; <span class="src-id">title</span>=\&quot;<span class="src-id">Page </span><span class="src-str"></span><span class="src-str">"</span>.<span class="src-var">$i</span>.<span class="src-str">&quot;\&quot;&gt;&quot;</span>.<span class="src-var">$i</span>.<span class="src-str">&quot;&lt;/a&gt;&quot;</span><span class="src-sym">;</span></span></li>
<li><a name="a2401"></a>&nbsp;</li>
<li><a name="a2402"></a></span><span class="src-str">                <span class="src-var">$page_list</span> .= <span class="src-str">&quot; &quot;</span><span class="src-sym">;</span></span></li>
<li><a name="a2403"></a></span><span class="src-str">            <span class="src-sym">}</span></span></li>
<li><a name="a2404"></a></span><span class="src-str">        <span class="src-sym">}</span></span></li>
<li><a name="a2405"></a>&nbsp;</li>
<li><a name="a2406"></a></span><span class="src-str">        <span class="src-comm">/* Print the Next and Last page links if necessary */</span></span></li>
<li><a name="a2407"></a></span><span class="src-str">        <span class="src-key">if</span><span class="src-sym">((</span><span class="src-var">$this</span></span><span class="src-sym">-&gt;</span><span class="src-var">page</span>+<span class="src-num">1</span><span class="src-sym">) </span>&lt;= <span class="src-var">$this</span><span class="src-sym">-&gt;</span><span class="src-var">pages</span><span class="src-sym">)</span></li>
<li><a name="a2408"></a>            <span class="src-var">$page_list </span>.= </span><span class="src-str"><span class="src-str">"</span>&lt;<span class="src-id">a</span> <span class="src-id">href</span>=\&quot;?<span class="src-var">$this</span></span><span class="src-sym">-&gt;</span><span class="src-var">paging_extra_params</span>&amp;<span class="src-id">page</span>=</span><span class="src-str"><span class="src-str">"</span>.<span class="src-sym">(</span><span class="src-var">$this</span></span><span class="src-sym">-&gt;</span><span class="src-var">page</span>+<span class="src-num">1</span><span class="src-sym">)</span>.</span><span class="src-str"><span class="src-str">"</span>&amp;<span class="src-id">per_page</span>=<span class="src-var">$this</span></span><span class="src-sym">-&gt;</span><span class="src-var">rows_per_page</span>\&quot; <span class="src-id">class</span>=\&quot;<span class="src-id">page_list</span>\&quot; <span class="src-id">title</span>=\&quot;<span class="src-id">Next Page</span>\&quot;&gt;&gt;&lt;/<span class="src-id">a</span>&gt; </span><span class="src-str"><span class="src-str">"</span><span class="src-sym">;</span></span></li>
<li><a name="a2409"></a>&nbsp;</li>
<li><a name="a2410"></a></span><span class="src-str">        <span class="src-key">if</span><span class="src-sym">((</span><span class="src-var">$this</span></span><span class="src-sym">-&gt;</span><span class="src-var">page </span>!= <span class="src-var">$this</span><span class="src-sym">-&gt;</span><span class="src-var">pages</span><span class="src-sym">) </span>&amp;&amp; <span class="src-sym">(</span><span class="src-var">$this</span><span class="src-sym">-&gt;</span><span class="src-var">pages </span>!= <span class="src-num">0</span><span class="src-sym">))</span></li>
<li><a name="a2411"></a>            <span class="src-var">$page_list </span>.= </span><span class="src-str"><span class="src-str">"</span>&lt;<span class="src-id">a</span> <span class="src-id">href</span>=\&quot;?<span class="src-var">$this</span></span><span class="src-sym">-&gt;</span><span class="src-var">paging_extra_params</span>&amp;<span class="src-id">page</span>=</span><span class="src-str"><span class="src-str">"</span>.<span class="src-var">$this</span></span><span class="src-sym">-&gt;</span><span class="src-var">pages</span>.</span><span class="src-str"><span class="src-str">"</span>&amp;<span class="src-id">per_page</span>=<span class="src-var">$this</span></span><span class="src-sym">-&gt;</span><span class="src-var">rows_per_page</span>\&quot; <span class="src-id">class</span>=\&quot;<span class="src-id">page_list</span>\&quot; <span class="src-id">title</span>=\&quot;<span class="src-id">Last Page</span>\&quot;&gt;&gt;&gt;&lt;/<span class="src-id">a</span>&gt; </span><span class="src-str"><span class="src-str">"</span><span class="src-sym">;</span></span></li>
<li><a name="a2412"></a>&nbsp;</li>
<li><a name="a2413"></a></span><span class="src-str">        <span class="src-var">$page_list</span> .= <span class="src-str">&quot;\n&quot;</span><span class="src-sym">;</span></span></li>
<li><a name="a2414"></a>&nbsp;</li>
<li><a name="a2415"></a></span><span class="src-str">        <span class="src-comm">//error_log(&quot;Page list=[$page_list]&quot;);</span></span></li>
<li><a name="a2416"></a></span><span class="src-str"><span class="src-comm"></span>        <span class="src-key">return</span> <span class="src-var">$page_list</span><span class="src-sym">;</span></span></li>
<li><a name="a2417"></a></span><span class="src-str">    <span class="src-sym">}</span></span></li>
<li><a name="a2418"></a>&nbsp;</li>
<li><a name="a2419"></a></span><span class="src-str"><span class="src-sym">}</span></span></li>
<li><a name="a2420"></a>&nbsp;</li>
<li><a name="a2421"></a></span><span class="src-str"><span class="src-comm">// -- set Emacs parameters --</span></span></li>
<li><a name="a2422"></a></span><span class="src-str"><span class="src-comm">// Local variables:</span></span></li>
<li><a name="a2423"></a></span><span class="src-str"><span class="src-comm">// tab-width: 4</span></span></li>
<li><a name="a2424"></a></span><span class="src-str"><span class="src-comm">// c-basic-offset: 4</span></span></li>
<li><a name="a2425"></a></span><span class="src-str"><span class="src-comm">// c-hanging-comment-ender-p: nil</span></span></li>
<li><a name="a2426"></a></span><span class="src-str"><span class="src-comm">// indent-tabs-mode: nil</span></span></li>
<li><a name="a2427"></a></span><span class="src-str"><span class="src-comm">// End:</span></span></li>
</ol></pre></div>
</div>
        <div class="credit">
		    <hr />
		    Documentation generated on Thu, 04 May 2006 19:47:11 -0600 by <a href="http://www.phpdoc.org">phpDocumentor 1.3.0RC4</a>
	      </div>
      </td></tr></table>
    </td>
  </tr>
</table>

</body>
</html>
Return current item: PHP on Trax