<?xml version="1.0" encoding="UTF-8"?><rss version="2.0"
	xmlns:content="http://purl.org/rss/1.0/modules/content/"
	xmlns:dc="http://purl.org/dc/elements/1.1/"
	xmlns:atom="http://www.w3.org/2005/Atom"
	xmlns:sy="http://purl.org/rss/1.0/modules/syndication/"
		>
<channel>
	<title>Comments for lukebaker.org</title>
	<atom:link href="http://lukebaker.org/comments/feed/" rel="self" type="application/rss+xml" />
	<link>http://lukebaker.org</link>
	<description>lukebaker.org</description>
	<lastBuildDate>Mon, 11 Jan 2010 14:09:40 +0000</lastBuildDate>
	<generator>http://wordpress.org/?v=2.9.2</generator>
	<sy:updatePeriod>hourly</sy:updatePeriod>
	<sy:updateFrequency>1</sy:updateFrequency>
		<item>
		<title>Comment on Documentation by Sebastian</title>
		<link>http://lukebaker.org/projects/activerecord-in-php/documentation/comment-page-1/#comment-22797</link>
		<dc:creator>Sebastian</dc:creator>
		<pubDate>Mon, 11 Jan 2010 14:09:40 +0000</pubDate>
		<guid isPermaLink="false">http://lukebaker.org/projects/activerecord-in-php/documentation/#comment-22797</guid>
		<description>An additional function: count
Same parameters as find, but only returns the number of rows.

Code:

In ActiveRecord.php add:

static function count($class, $options=null) {
    $class = str_replace(&#039;Base&#039;, &#039;&#039;, $class);
    $query = self::generate_count_query($class, $options);
    $rows = self::query($query);
    
    return $rows[0][&#039;COUNT(*)&#039;];
    
  }
	
  function generate_count_query($class_name, $options){
  	$item = new $class_name;
  	
  	/* regex for limit, order, group */
  	$regex = &#039;/^[A-Za-z0-9\-_ ,\(\)]+$/&#039;;
  	if (!isset($options[&#039;limit&#039;]) &#124;&#124; !preg_match($regex, $options[&#039;limit&#039;]))
  	$options[&#039;limit&#039;] = &#039;&#039;;
  	if (!isset($options[&#039;order&#039;]) &#124;&#124; !preg_match($regex, $options[&#039;order&#039;]))
  	$options[&#039;order&#039;] = &#039;&#039;;
  	if (!isset($options[&#039;group&#039;]) &#124;&#124; !preg_match($regex, $options[&#039;group&#039;]))
  	$options[&#039;group&#039;] = &#039;&#039;;
  	if (!isset($options[&#039;offset&#039;]) &#124;&#124; !is_numeric($options[&#039;offset&#039;]))
  	$options[&#039;offset&#039;] = &#039;&#039;;

  	$select = &#039;COUNT(*)&#039;;
  	
  	if (isset($options[&#039;conditions&#039;]))
  		$where = (isset($where) &amp;&amp; $where) ? $where . &quot; AND (&quot; . $options[&#039;conditions&#039;] .&quot;)&quot; : $options[&#039;conditions&#039;];
  	if ($options[&#039;offset&#039;])
  		$offset = $options[&#039;offset&#039;];
  	if ($options[&#039;limit&#039;] &amp;&amp; !isset($limit))
  		$limit = $options[&#039;limit&#039;];

  	$joins = array();
  	$tables_to_columns = array();
  	

  	$query  = &quot;SELECT $select FROM {$item-&gt;table_name}&quot;;
  	$query .= (isset($where)) ? &quot; WHERE $where&quot; : &quot;&quot;;
  	$query .= ($options[&#039;group&#039;]) ? &quot; GROUP BY {$options[&#039;group&#039;]}&quot; : &quot;&quot;;
  	$query .= ($options[&#039;order&#039;]) ? &quot; ORDER BY {$options[&#039;order&#039;]}&quot; : &quot;&quot;;
  	$query .= (isset($limit) &amp;&amp; $limit) ? &quot; LIMIT $limit&quot; : &quot;&quot;;
  	$query .= (isset($offset) &amp;&amp; $offset) ? &quot; OFFSET $offset&quot; : &quot;&quot;;
	
  	return $query;
  }

In ModelBase.tpl add inside the Class definition:

static function count($options=null){
    return parent::count(__CLASS__,$options);
  }</description>
		<content:encoded><![CDATA[<p>An additional function: count<br />
Same parameters as find, but only returns the number of rows.</p>
<p>Code:</p>
<p>In ActiveRecord.php add:</p>
<p>static function count($class, $options=null) {<br />
    $class = str_replace(&#8216;Base&#8217;, &#8221;, $class);<br />
    $query = self::generate_count_query($class, $options);<br />
    $rows = self::query($query);</p>
<p>    return $rows[0]['COUNT(*)'];</p>
<p>  }</p>
<p>  function generate_count_query($class_name, $options){<br />
  	$item = new $class_name;</p>
<p>  	/* regex for limit, order, group */<br />
  	$regex = &#8216;/^[A-Za-z0-9\-_ ,\(\)]+$/&#8217;;<br />
  	if (!isset($options['limit']) || !preg_match($regex, $options['limit']))<br />
  	$options['limit'] = &#8221;;<br />
  	if (!isset($options['order']) || !preg_match($regex, $options['order']))<br />
  	$options['order'] = &#8221;;<br />
  	if (!isset($options['group']) || !preg_match($regex, $options['group']))<br />
  	$options['group'] = &#8221;;<br />
  	if (!isset($options['offset']) || !is_numeric($options['offset']))<br />
  	$options['offset'] = &#8221;;</p>
<p>  	$select = &#8216;COUNT(*)&#8217;;</p>
<p>  	if (isset($options['conditions']))<br />
  		$where = (isset($where) &amp;&amp; $where) ? $where . &#8221; AND (&#8221; . $options['conditions'] .&#8221;)&#8221; : $options['conditions'];<br />
  	if ($options['offset'])<br />
  		$offset = $options['offset'];<br />
  	if ($options['limit'] &amp;&amp; !isset($limit))<br />
  		$limit = $options['limit'];</p>
<p>  	$joins = array();<br />
  	$tables_to_columns = array();</p>
<p>  	$query  = &#8220;SELECT $select FROM {$item-&gt;table_name}&#8221;;<br />
  	$query .= (isset($where)) ? &#8221; WHERE $where&#8221; : &#8220;&#8221;;<br />
  	$query .= ($options['group']) ? &#8221; GROUP BY {$options['group']}&#8221; : &#8220;&#8221;;<br />
  	$query .= ($options['order']) ? &#8221; ORDER BY {$options['order']}&#8221; : &#8220;&#8221;;<br />
  	$query .= (isset($limit) &amp;&amp; $limit) ? &#8221; LIMIT $limit&#8221; : &#8220;&#8221;;<br />
  	$query .= (isset($offset) &amp;&amp; $offset) ? &#8221; OFFSET $offset&#8221; : &#8220;&#8221;;</p>
<p>  	return $query;<br />
  }</p>
<p>In ModelBase.tpl add inside the Class definition:</p>
<p>static function count($options=null){<br />
    return parent::count(__CLASS__,$options);<br />
  }</p>
]]></content:encoded>
	</item>
	<item>
		<title>Comment on PHP and Named Parameters by PHP User</title>
		<link>http://lukebaker.org/archives/2007/03/01/php-and-named-parameters/comment-page-1/#comment-22783</link>
		<dc:creator>PHP User</dc:creator>
		<pubDate>Fri, 08 Jan 2010 05:32:34 +0000</pubDate>
		<guid isPermaLink="false">http://lukebaker.org/archives/2007/03/01/php-and-named-parameters/#comment-22783</guid>
		<description>I know this is an old post, but take a look at this ==&gt;

http://www.hotscripts.com/blog/php-parameter-skipping/

It also covers naming.  Pretty neat.</description>
		<content:encoded><![CDATA[<p>I know this is an old post, but take a look at this ==&gt;</p>
<p><a href="http://www.hotscripts.com/blog/php-parameter-skipping/" rel="nofollow">http://www.hotscripts.com/blog/php-parameter-skipping/</a></p>
<p>It also covers naming.  Pretty neat.</p>
]]></content:encoded>
	</item>
	<item>
		<title>Comment on Documentation by Matthieu</title>
		<link>http://lukebaker.org/projects/activerecord-in-php/documentation/comment-page-1/#comment-22775</link>
		<dc:creator>Matthieu</dc:creator>
		<pubDate>Wed, 06 Jan 2010 18:32:00 +0000</pubDate>
		<guid isPermaLink="false">http://lukebaker.org/projects/activerecord-in-php/documentation/#comment-22775</guid>
		<description>Another bug i found:

in file AcitveRecord.php, on around 317, change this:

if ($table_name == ActiveRecordInflector::pluralize($assoc_name))

to this:

if ($table_name == ActiveRecordInflector::tableize($assoc_name))</description>
		<content:encoded><![CDATA[<p>Another bug i found:</p>
<p>in file AcitveRecord.php, on around 317, change this:</p>
<p>if ($table_name == ActiveRecordInflector::pluralize($assoc_name))</p>
<p>to this:</p>
<p>if ($table_name == ActiveRecordInflector::tableize($assoc_name))</p>
]]></content:encoded>
	</item>
	<item>
		<title>Comment on Documentation by Matthieu</title>
		<link>http://lukebaker.org/projects/activerecord-in-php/documentation/comment-page-1/#comment-22773</link>
		<dc:creator>Matthieu</dc:creator>
		<pubDate>Wed, 06 Jan 2010 16:36:45 +0000</pubDate>
		<guid isPermaLink="false">http://lukebaker.org/projects/activerecord-in-php/documentation/#comment-22773</guid>
		<description>Little bug correction:

in HasMany.php, around line 58, change this:

        else {
          // TODO: $this-&gt;options[&#039;through&#039;] is not necessarily the table name
          $collection = call_user_func_array(array($this-&gt;dest_class, &#039;find&#039;),
            array(&#039;all&#039;,
              array(&#039;include&#039; =&gt; $this-&gt;options[&#039;through&#039;],
                &#039;conditions&#039; =&gt; &quot;{$this-&gt;options[&#039;through&#039;]}.{$this-&gt;foreign_key} = &quot;.$source-&gt;{$source-&gt;get_primary_key()})));
        }

to this :

        else {
          $through_table = ActiveRecordInflector::tableize($this-&gt;options[&#039;through&#039;]);
          $collection = call_user_func_array(array($this-&gt;dest_class, &#039;find&#039;),
            array(&#039;all&#039;,
              array(&#039;include&#039; =&gt; $this-&gt;options[&#039;through&#039;],
                &#039;conditions&#039; =&gt; &quot;{$through_table}.{$this-&gt;foreign_key} = &quot;.$source-&gt;{$source-&gt;get_primary_key()})));
        }


And around line 144, modify this:

      $join = &quot;LEFT OUTER JOIN {$this-&gt;options[&#039;through&#039;]} ON &quot;
            . &quot;{$this-&gt;options[&#039;through&#039;]}.{$this-&gt;foreign_key} = $source_table.&quot;.$source_inst-&gt;get_primary_key() .&quot; &quot;
            . &quot;LEFT OUTER JOIN $dest_table ON &quot;
            . &quot;$dest_table.&quot;.$dest_inst-&gt;get_primary_key() .&quot; = {$this-&gt;options[&#039;through&#039;]}.&quot; . ActiveRecordInflector::foreign_key($this-&gt;dest_class);

to this:

      $through_table = ActiveRecordInflector::tableize($this-&gt;options[&#039;through&#039;]);
      $join = &quot;LEFT OUTER JOIN {$through_table} ON &quot;
            . &quot;{$through_table}.{$this-&gt;foreign_key} = $source_table.&quot;.$source_inst-&gt;get_primary_key() .&quot; &quot;
            . &quot;LEFT OUTER JOIN $dest_table ON &quot;
            . &quot;$dest_table.&quot;.$dest_inst-&gt;get_primary_key() .&quot; = {$through_table}.&quot; . ActiveRecordInflector::foreign_key($this-&gt;dest_class);</description>
		<content:encoded><![CDATA[<p>Little bug correction:</p>
<p>in HasMany.php, around line 58, change this:</p>
<p>        else {<br />
          // TODO: $this-&gt;options['through'] is not necessarily the table name<br />
          $collection = call_user_func_array(array($this-&gt;dest_class, &#8216;find&#8217;),<br />
            array(&#8216;all&#8217;,<br />
              array(&#8216;include&#8217; =&gt; $this-&gt;options['through'],<br />
                &#8216;conditions&#8217; =&gt; &#8220;{$this-&gt;options['through']}.{$this-&gt;foreign_key} = &#8220;.$source-&gt;{$source-&gt;get_primary_key()})));<br />
        }</p>
<p>to this :</p>
<p>        else {<br />
          $through_table = ActiveRecordInflector::tableize($this-&gt;options['through']);<br />
          $collection = call_user_func_array(array($this-&gt;dest_class, &#8216;find&#8217;),<br />
            array(&#8216;all&#8217;,<br />
              array(&#8216;include&#8217; =&gt; $this-&gt;options['through'],<br />
                &#8216;conditions&#8217; =&gt; &#8220;{$through_table}.{$this-&gt;foreign_key} = &#8220;.$source-&gt;{$source-&gt;get_primary_key()})));<br />
        }</p>
<p>And around line 144, modify this:</p>
<p>      $join = &#8220;LEFT OUTER JOIN {$this-&gt;options['through']} ON &#8221;<br />
            . &#8220;{$this-&gt;options['through']}.{$this-&gt;foreign_key} = $source_table.&#8221;.$source_inst-&gt;get_primary_key() .&#8221; &#8221;<br />
            . &#8220;LEFT OUTER JOIN $dest_table ON &#8221;<br />
            . &#8220;$dest_table.&#8221;.$dest_inst-&gt;get_primary_key() .&#8221; = {$this-&gt;options['through']}.&#8221; . ActiveRecordInflector::foreign_key($this-&gt;dest_class);</p>
<p>to this:</p>
<p>      $through_table = ActiveRecordInflector::tableize($this-&gt;options['through']);<br />
      $join = &#8220;LEFT OUTER JOIN {$through_table} ON &#8221;<br />
            . &#8220;{$through_table}.{$this-&gt;foreign_key} = $source_table.&#8221;.$source_inst-&gt;get_primary_key() .&#8221; &#8221;<br />
            . &#8220;LEFT OUTER JOIN $dest_table ON &#8221;<br />
            . &#8220;$dest_table.&#8221;.$dest_inst-&gt;get_primary_key() .&#8221; = {$through_table}.&#8221; . ActiveRecordInflector::foreign_key($this-&gt;dest_class);</p>
]]></content:encoded>
	</item>
	<item>
		<title>Comment on Praying Mantis by pearl</title>
		<link>http://lukebaker.org/archives/2005/09/06/praying-mantis/comment-page-1/#comment-21982</link>
		<dc:creator>pearl</dc:creator>
		<pubDate>Mon, 03 Aug 2009 07:44:44 +0000</pubDate>
		<guid isPermaLink="false">http://lukebaker.org/?p=34#comment-21982</guid>
		<description>I love the praying mantis
im getting a pet one soon
bye</description>
		<content:encoded><![CDATA[<p>I love the praying mantis<br />
im getting a pet one soon<br />
bye</p>
]]></content:encoded>
	</item>
	<item>
		<title>Comment on ActiveRecord in PHP by Kalle Henriksson</title>
		<link>http://lukebaker.org/projects/activerecord-in-php/comment-page-1/#comment-21719</link>
		<dc:creator>Kalle Henriksson</dc:creator>
		<pubDate>Wed, 15 Jul 2009 07:30:47 +0000</pubDate>
		<guid isPermaLink="false">http://lukebaker.org/projects/activerecord-in-php/#comment-21719</guid>
		<description>Sorry guys! My bad! If I had paid a little more attention to what I was doing this would not have happened. My relationship declarations in the models are wrong. Where it says &quot;categories&quot; it should be &quot;productcategories&quot;. And &quot;categorizations&quot; should be &quot;productcategorizations&quot;.

Maan... I&#039;ll try to hide my shame behind the fact that I&#039;m a PHP noob :o) (but even noobs can often read and spell correctly, can&#039;t they? Darn!) ;o)

Thanks!</description>
		<content:encoded><![CDATA[<p>Sorry guys! My bad! If I had paid a little more attention to what I was doing this would not have happened. My relationship declarations in the models are wrong. Where it says &#8220;categories&#8221; it should be &#8220;productcategories&#8221;. And &#8220;categorizations&#8221; should be &#8220;productcategorizations&#8221;.</p>
<p>Maan&#8230; I&#8217;ll try to hide my shame behind the fact that I&#8217;m a PHP noob :o) (but even noobs can often read and spell correctly, can&#8217;t they? Darn!) ;o)</p>
<p>Thanks!</p>
]]></content:encoded>
	</item>
	<item>
		<title>Comment on ActiveRecord in PHP by Kalle Henriksson</title>
		<link>http://lukebaker.org/projects/activerecord-in-php/comment-page-1/#comment-21707</link>
		<dc:creator>Kalle Henriksson</dc:creator>
		<pubDate>Tue, 14 Jul 2009 20:28:46 +0000</pubDate>
		<guid isPermaLink="false">http://lukebaker.org/projects/activerecord-in-php/#comment-21707</guid>
		<description>Looks like my example code went through some security checks there. ;o) Anyway... I have two simple foreach loops. One outer, going through my products and printing their names and an inner loop going through and printing the names of the categories for each product. Simple enough. But h-nooo... It fails, giving me the above error.

Anyone?

Thanks!</description>
		<content:encoded><![CDATA[<p>Looks like my example code went through some security checks there. ;o) Anyway&#8230; I have two simple foreach loops. One outer, going through my products and printing their names and an inner loop going through and printing the names of the categories for each product. Simple enough. But h-nooo&#8230; It fails, giving me the above error.</p>
<p>Anyone?</p>
<p>Thanks!</p>
]]></content:encoded>
	</item>
	<item>
		<title>Comment on ActiveRecord in PHP by Kalle Henriksson</title>
		<link>http://lukebaker.org/projects/activerecord-in-php/comment-page-1/#comment-21699</link>
		<dc:creator>Kalle Henriksson</dc:creator>
		<pubDate>Tue, 14 Jul 2009 13:06:55 +0000</pubDate>
		<guid isPermaLink="false">http://lukebaker.org/projects/activerecord-in-php/#comment-21699</guid>
		<description>Hi..!

Iv&#039;e run into a small problem with a very basic test project of mine. I&#039;ve got 3 tables: products, productcategories and productcategorization. The last one bacause och my many:many relationship between products and productcategories. The tables all have some data.



The relationships between my models are set up as follow...

Product.php
protected $has_many = array(&#039;productcategorizations&#039;, array(&#039;categories&#039; =&gt; array(&#039;through&#039; =&gt; &#039;categorizations&#039;)));

Productcategory.php
protected $has_many = array(&#039;categorizations&#039;, array(&#039;products&#039; =&gt; array(&#039;through&#039; =&gt; &#039;categorizations&#039;)));

Productcategorization.php
protected $belongs_to = array(&#039;product&#039;, &#039;category&#039;);



So far so good... But then I run my script...

 $p){
		echo(&#039;Product: &#039;.$p-&gt;text.&#039;&#039;);
		foreach($p-&gt;categories as $pci =&gt; $pc){
			echo(&#039;Category: &#039;.$pc-&gt;text.&#039;&#039;);
		}
		echo(&#039;&#039;);
	}
?&gt;

...and it crashes...

I get the following long message...

PHP Warning: call_user_func_array() [function.call-user-func-array]: First argument is expected to be a valid callback, &#039;Category::find&#039; was given in blablabla...\server\models\activerecord\HasMany.php on line 64 PHP Warning: call_user_func_array() [function.call-user-func-array]: First argument is expected to be a valid callback, &#039;Category::find&#039; was given in blablabla...\server\models\activerecord\HasMany.php on line 64 PHP Warning: call_user_func_array() [function.call-user-func-array]: First argument is expected to be a valid callback, &#039;Category::find&#039; was given in blablabla...\server\models\activerecord\HasMany.php on line 64 


Does anyone know what I&#039;m doing wrong? I&#039;ll keep digging and post the solution if I come up with one. ;o)

Thanks!

PS. Maan I love this code. Coding PHP is sooo much easier now..!</description>
		<content:encoded><![CDATA[<p>Hi..!</p>
<p>Iv&#8217;e run into a small problem with a very basic test project of mine. I&#8217;ve got 3 tables: products, productcategories and productcategorization. The last one bacause och my many:many relationship between products and productcategories. The tables all have some data.</p>
<p>The relationships between my models are set up as follow&#8230;</p>
<p>Product.php<br />
protected $has_many = array(&#8216;productcategorizations&#8217;, array(&#8216;categories&#8217; =&gt; array(&#8216;through&#8217; =&gt; &#8216;categorizations&#8217;)));</p>
<p>Productcategory.php<br />
protected $has_many = array(&#8216;categorizations&#8217;, array(&#8216;products&#8217; =&gt; array(&#8216;through&#8217; =&gt; &#8216;categorizations&#8217;)));</p>
<p>Productcategorization.php<br />
protected $belongs_to = array(&#8216;product&#8217;, &#8216;category&#8217;);</p>
<p>So far so good&#8230; But then I run my script&#8230;</p>
<p> $p){<br />
		echo(&#8216;Product: &#8216;.$p-&gt;text.&#8221;);<br />
		foreach($p-&gt;categories as $pci =&gt; $pc){<br />
			echo(&#8216;Category: &#8216;.$pc-&gt;text.&#8221;);<br />
		}<br />
		echo(&#8221;);<br />
	}<br />
?&gt;</p>
<p>&#8230;and it crashes&#8230;</p>
<p>I get the following long message&#8230;</p>
<p>PHP Warning: call_user_func_array() [function.call-user-func-array]: First argument is expected to be a valid callback, &#8216;Category::find&#8217; was given in blablabla&#8230;\server\models\activerecord\HasMany.php on line 64 PHP Warning: call_user_func_array() [function.call-user-func-array]: First argument is expected to be a valid callback, &#8216;Category::find&#8217; was given in blablabla&#8230;\server\models\activerecord\HasMany.php on line 64 PHP Warning: call_user_func_array() [function.call-user-func-array]: First argument is expected to be a valid callback, &#8216;Category::find&#8217; was given in blablabla&#8230;\server\models\activerecord\HasMany.php on line 64 </p>
<p>Does anyone know what I&#8217;m doing wrong? I&#8217;ll keep digging and post the solution if I come up with one. ;o)</p>
<p>Thanks!</p>
<p>PS. Maan I love this code. Coding PHP is sooo much easier now..!</p>
]]></content:encoded>
	</item>
	<item>
		<title>Comment on Documentation by Fyodor</title>
		<link>http://lukebaker.org/projects/activerecord-in-php/documentation/comment-page-1/#comment-21589</link>
		<dc:creator>Fyodor</dc:creator>
		<pubDate>Mon, 29 Jun 2009 11:48:29 +0000</pubDate>
		<guid isPermaLink="false">http://lukebaker.org/projects/activerecord-in-php/documentation/#comment-21589</guid>
		<description>Sorry for code formatting and my bad English. ;)</description>
		<content:encoded><![CDATA[<p>Sorry for code formatting and my bad English. ;)</p>
]]></content:encoded>
	</item>
	<item>
		<title>Comment on Documentation by Fyodor</title>
		<link>http://lukebaker.org/projects/activerecord-in-php/documentation/comment-page-1/#comment-21588</link>
		<dc:creator>Fyodor</dc:creator>
		<pubDate>Mon, 29 Jun 2009 11:47:16 +0000</pubDate>
		<guid isPermaLink="false">http://lukebaker.org/projects/activerecord-in-php/documentation/#comment-21588</guid>
		<description>For those seeking to :foreign_key and :class_name options for associations, you may modify following classes:

1. Association in Association.php:

  ...
  function __construct($source, $dest, $options=null) {
    $this-&gt;source_class = get_class($source);

    if (!empty($options[&#039;foreign_key&#039;])) {
      $this-&gt;foreign_key = $options[&#039;foreign_key&#039;];
    }

    if (!empty($options[&#039;class_name&#039;])) {
      $this-&gt;dest_class = $options[&#039;class_name&#039;];
    } else {
      $this-&gt;dest_class = ActiveRecordInflector::classify($dest);
    }

    $this-&gt;options = $options;
  }
  ...

2. BelongsTo in BelongsTo.php:
  ...
  function __construct(&amp;$source, $dest, $options=null) {
    parent::__construct($source, $dest, $options);
    if (!isset($this-&gt;foreign_key)) {
      $this-&gt;foreign_key = ActiveRecordInflector::foreign_key($this-&gt;dest_class);
    }
  }
  ...

3. HasMany in HasMany.php, HasOne in HasOne.php:
  ...
  function __construct(&amp;$source, $dest, $options=null) {
    parent::__construct($source, $dest, $options);
    if (!isset($this-&gt;foreign_key)) {
      $this-&gt;foreign_key = ActiveRecordInflector::foreign_key($this-&gt;source_class);
    }
  }
  ...

Example:

class Product extends ProductBase {
  protected $belongs_to = array(array(&#039;color1&#039; =&gt; array(&#039;class_name&#039; =&gt; &#039;Color&#039;, &#039;foreign_key&#039; =&gt; &#039;color1&#039;)), array(&#039;color2&#039; =&gt; array(&#039;class_name&#039; =&gt; &#039;Color&#039;, &#039;foreign_key&#039; =&gt; &#039;color2&#039;)), array(&#039;color3&#039; =&gt; array(&#039;class_name&#039; =&gt; &#039;Color&#039;, &#039;foreign_key&#039; =&gt; &#039;color3&#039;)));
}

Solution is not perfect, just quick patch.</description>
		<content:encoded><![CDATA[<p>For those seeking to :foreign_key and :class_name options for associations, you may modify following classes:</p>
<p>1. Association in Association.php:</p>
<p>  &#8230;<br />
  function __construct($source, $dest, $options=null) {<br />
    $this-&gt;source_class = get_class($source);</p>
<p>    if (!empty($options['foreign_key'])) {<br />
      $this-&gt;foreign_key = $options['foreign_key'];<br />
    }</p>
<p>    if (!empty($options['class_name'])) {<br />
      $this-&gt;dest_class = $options['class_name'];<br />
    } else {<br />
      $this-&gt;dest_class = ActiveRecordInflector::classify($dest);<br />
    }</p>
<p>    $this-&gt;options = $options;<br />
  }<br />
  &#8230;</p>
<p>2. BelongsTo in BelongsTo.php:<br />
  &#8230;<br />
  function __construct(&amp;$source, $dest, $options=null) {<br />
    parent::__construct($source, $dest, $options);<br />
    if (!isset($this-&gt;foreign_key)) {<br />
      $this-&gt;foreign_key = ActiveRecordInflector::foreign_key($this-&gt;dest_class);<br />
    }<br />
  }<br />
  &#8230;</p>
<p>3. HasMany in HasMany.php, HasOne in HasOne.php:<br />
  &#8230;<br />
  function __construct(&amp;$source, $dest, $options=null) {<br />
    parent::__construct($source, $dest, $options);<br />
    if (!isset($this-&gt;foreign_key)) {<br />
      $this-&gt;foreign_key = ActiveRecordInflector::foreign_key($this-&gt;source_class);<br />
    }<br />
  }<br />
  &#8230;</p>
<p>Example:</p>
<p>class Product extends ProductBase {<br />
  protected $belongs_to = array(array(&#8216;color1&#8242; =&gt; array(&#8216;class_name&#8217; =&gt; &#8216;Color&#8217;, &#8216;foreign_key&#8217; =&gt; &#8216;color1&#8242;)), array(&#8216;color2&#8242; =&gt; array(&#8216;class_name&#8217; =&gt; &#8216;Color&#8217;, &#8216;foreign_key&#8217; =&gt; &#8216;color2&#8242;)), array(&#8216;color3&#8242; =&gt; array(&#8216;class_name&#8217; =&gt; &#8216;Color&#8217;, &#8216;foreign_key&#8217; =&gt; &#8216;color3&#8242;)));<br />
}</p>
<p>Solution is not perfect, just quick patch.</p>
]]></content:encoded>
	</item>
</channel>
</rss>

<!-- Dynamic Page Served (once) in 0.398 seconds -->
