<?xml version="1.0" encoding="UTF-8"?>
<commit>
  <added type="array"/>
  <modified type="array">
    <modified>
      <diff>@@ -41,39 +41,82 @@
             $this-&gt;belongs_to = (array) $this-&gt;belongs_to;
             $this-&gt;has_many   = (array) $this-&gt;has_many;
             $this-&gt;has_one    = (array) $this-&gt;has_one;
+
             if (in_array($name, $this-&gt;belongs_to) or isset($this-&gt;belongs_to[$name])) {
                 $class = (isset($this-&gt;belongs_to[$name])) ? $this-&gt;belongs_to[$name] : $name ;
                 if (isset($this-&gt;belongs_to[$name])) {
                     $opts =&amp; $this-&gt;belongs_to[$name];
                     $model = oneof(@$opts[&quot;model&quot;], $name);
+
+                    if (preg_match(&quot;/^\(([a-z0-9_]+)\)$/&quot;, $model, $match))
+                        $model = $this-&gt;$match[1];
+
                     $match = oneof(@$opts[&quot;by&quot;], strtolower($name));
-                    $where = array_merge(array(&quot;id&quot; =&gt; $this-&gt;{$match.&quot;_id&quot;}),
-                                         (array) @$opts[&quot;where&quot;]);
+
+                    fallback($opts[&quot;where&quot;], array(&quot;id&quot; =&gt; $this-&gt;{$match.&quot;_id&quot;}));
+
+                    $opts[&quot;where&quot;] = (array) $opts[&quot;where&quot;];
+                    foreach ($opts[&quot;where&quot;] as &amp;$val)
+                        if (preg_match(&quot;/^\(([a-z0-9_]+)\)$/&quot;, $val, $match))
+                            $val = $this-&gt;$match[1];
+
+                    fallback($opts[&quot;placeholders&quot;], $placeholders);
                 } else {
                     $model = $name;
-                    $where = array(&quot;id&quot; =&gt; $this-&gt;{$name.&quot;_id&quot;});
+                    $opts = array(&quot;where&quot; =&gt; array(&quot;id&quot; =&gt; $this-&gt;{$name.&quot;_id&quot;}));
                 }
 
-                return $this-&gt;$name = new $model(null, array(&quot;where&quot; =&gt; $where));
+                return $this-&gt;$name = new $model(null, $opts);
             } elseif (in_array($name, $this-&gt;has_many) or isset($this-&gt;has_many[$name])) {
                 if (isset($this-&gt;has_many[$name])) {
                     $opts =&amp; $this-&gt;has_many[$name];
-                    $model = oneof($opts[&quot;model&quot;], $name);
+                    $model = oneof(@$opts[&quot;model&quot;], depluralize($name));
+
+                    if (preg_match(&quot;/^\(([a-z0-9_]+)\)$/&quot;, $model, $match))
+                        $model = $this-&gt;$match[1];
+
                     $match = oneof(@$opts[&quot;by&quot;], strtolower($name));
-                    $where = array_merge(array($match.&quot;_id&quot; =&gt; $this-&gt;id),
-                                         (array) @$opts[&quot;where&quot;]);
+
+                    fallback($opts[&quot;where&quot;], array($match.&quot;_id&quot; =&gt; $this-&gt;id));
+
+                    $opts[&quot;where&quot;] = (array) $opts[&quot;where&quot;];
+                    foreach ($opts[&quot;where&quot;] as &amp;$val)
+                        if (preg_match(&quot;/^\(([a-z0-9_]+)\)$/&quot;, $val, $match))
+                            $val = $this-&gt;$match[1];
+
+                    fallback($opts[&quot;placeholders&quot;], $placeholders);
                 } else {
                     $model = depluralize($name);
                     $match = $model_name;
-                    $where = array(strtolower($match).&quot;_id&quot; =&gt; $this-&gt;id);
+                    $opts = array(&quot;where&quot; =&gt; array(strtolower($match).&quot;_id&quot; =&gt; $this-&gt;id),
+                                  &quot;placeholders&quot; =&gt; $placeholders);
                 }
 
                 return $this-&gt;$name = call_user_func(array($model, &quot;find&quot;),
-                                                     array(&quot;where&quot; =&gt; $where,
-                                                           &quot;placeholders&quot; =&gt; $placeholders));
+                                                     $opts);
             } elseif (in_array($name, $this-&gt;has_one)) {
-                $class = depluralize($name);
-                return $this-&gt;$name = new $class(null, array(&quot;where&quot; =&gt; array(strtolower($model_name).&quot;_id&quot; =&gt; $this-&gt;id)));
+                if (isset($this-&gt;has_one[$name])) {
+                    $opts =&amp; $this-&gt;has_one[$name];
+                    $model = oneof(@$opts[&quot;model&quot;], depluralize($name));
+
+                    if (preg_match(&quot;/^\(([a-z0-9_]+)\)$/&quot;, $model, $match))
+                        $model = $this-&gt;$match[1];
+
+                    $match = oneof(@$opts[&quot;by&quot;], strtolower($name));
+
+                    fallback($opts[&quot;where&quot;], array($match.&quot;_id&quot; =&gt; $this-&gt;id));
+
+                    $opts[&quot;where&quot;] = (array) $opts[&quot;where&quot;];
+                    foreach ($opts[&quot;where&quot;] as &amp;$val)
+                        if (preg_match(&quot;/^\(([a-z0-9_]+)\)$/&quot;, $val, $match))
+                            $val = $this-&gt;$match[1];
+                } else {
+                    $model = depluralize($name);
+                    $match = $model_name;
+                    $opts = array(&quot;where&quot; =&gt; array(strtolower($match).&quot;_id&quot; =&gt; $this-&gt;id));
+                }
+
+                return $this-&gt;$name = new $model(null, $opts);
             }
         }
 
@@ -413,3 +456,4 @@
             echo $before.'&lt;a href=&quot;'.Config::current()-&gt;chyrp_url.'/admin/?action=delete_'.$name.'&amp;amp;id='.$this-&gt;id.'&quot; title=&quot;Delete&quot; class=&quot;'.($classes ? $classes.&quot; &quot; : '').$name.'_delete_link delete_link&quot; id=&quot;'.$name.'_delete_'.$this-&gt;id.'&quot;&gt;'.$text.'&lt;/a&gt;'.$after;
         }
     }
+</diff>
      <filename>includes/class/Model.php</filename>
    </modified>
  </modified>
  <removed type="array"/>
  <parents type="array">
    <parent>
      <id>58f22264d5b39d8b43ec52330dea960f2f109b4a</id>
    </parent>
  </parents>
  <author>
    <name>Alex Suraci</name>
    <email>i.am@toogeneric.com</email>
  </author>
  <url>http://github.com/vito/chyrp/commit/ccaa664167b47343121200bb89d9bfbbe8f7b5fb</url>
  <id>ccaa664167b47343121200bb89d9bfbbe8f7b5fb</id>
  <committed-date>2008-11-21T14:35:36-08:00</committed-date>
  <authored-date>2008-11-21T14:35:36-08:00</authored-date>
  <message>More model relations flexibility.</message>
  <tree>5a9439839c077abb09a5c17701800b99cc732b24</tree>
  <committer>
    <name>Alex Suraci</name>
    <email>i.am@toogeneric.com</email>
  </committer>
</commit>
