0
$this->belongs_to = (array) $this->belongs_to;
0
$this->has_many = (array) $this->has_many;
0
$this->has_one = (array) $this->has_one;
0
if (in_array($name, $this->belongs_to) or isset($this->belongs_to[$name])) {
0
$class = (isset($this->belongs_to[$name])) ? $this->belongs_to[$name] : $name ;
0
if (isset($this->belongs_to[$name])) {
0
$opts =& $this->belongs_to[$name];
0
$model = oneof(@$opts["model"], $name);
0
+ if (preg_match("/^\(([a-z0-9_]+)\)$/", $model, $match))
0
+ $model = $this->$match[1];
0
$match = oneof(@$opts["by"], strtolower($name));
0
- $where = array_merge(array("id" => $this->{$match."_id"}),
0
- (array) @$opts["where"]);
0
+ fallback($opts["where"], array("id" => $this->{$match."_id"}));
0
+ $opts["where"] = (array) $opts["where"];
0
+ foreach ($opts["where"] as &$val)
0
+ if (preg_match("/^\(([a-z0-9_]+)\)$/", $val, $match))
0
+ $val = $this->$match[1];
0
+ fallback($opts["placeholders"], $placeholders);
0
- $
where = array("id" => $this->{$name."_id"});
0
+ $
opts = array("where" => array("id" => $this->{$name."_id"}));
0
- return $this->$name = new $model(null,
array("where" => $where));
0
+ return $this->$name = new $model(null,
$opts);
0
} elseif (in_array($name, $this->has_many) or isset($this->has_many[$name])) {
0
if (isset($this->has_many[$name])) {
0
$opts =& $this->has_many[$name];
0
- $model = oneof($opts["model"], $name);
0
+ $model = oneof(@$opts["model"], depluralize($name));
0
+ if (preg_match("/^\(([a-z0-9_]+)\)$/", $model, $match))
0
+ $model = $this->$match[1];
0
$match = oneof(@$opts["by"], strtolower($name));
0
- $where = array_merge(array($match."_id" => $this->id),
0
- (array) @$opts["where"]);
0
+ fallback($opts["where"], array($match."_id" => $this->id));
0
+ $opts["where"] = (array) $opts["where"];
0
+ foreach ($opts["where"] as &$val)
0
+ if (preg_match("/^\(([a-z0-9_]+)\)$/", $val, $match))
0
+ $val = $this->$match[1];
0
+ fallback($opts["placeholders"], $placeholders);
0
$model = depluralize($name);
0
- $where = array(strtolower($match)."_id" => $this->id);
0
+ $opts = array("where" => array(strtolower($match)."_id" => $this->id),
0
+ "placeholders" => $placeholders);
0
return $this->$name = call_user_func(array($model, "find"),
0
- array("where" => $where,
0
- "placeholders" => $placeholders));
0
} elseif (in_array($name, $this->has_one)) {
0
- $class = depluralize($name);
0
- return $this->$name = new $class(null, array("where" => array(strtolower($model_name)."_id" => $this->id)));
0
+ if (isset($this->has_one[$name])) {
0
+ $opts =& $this->has_one[$name];
0
+ $model = oneof(@$opts["model"], depluralize($name));
0
+ if (preg_match("/^\(([a-z0-9_]+)\)$/", $model, $match))
0
+ $model = $this->$match[1];
0
+ $match = oneof(@$opts["by"], strtolower($name));
0
+ fallback($opts["where"], array($match."_id" => $this->id));
0
+ $opts["where"] = (array) $opts["where"];
0
+ foreach ($opts["where"] as &$val)
0
+ if (preg_match("/^\(([a-z0-9_]+)\)$/", $val, $match))
0
+ $val = $this->$match[1];
0
+ $model = depluralize($name);
0
+ $opts = array("where" => array(strtolower($match)."_id" => $this->id));
0
+ return $this->$name = new $model(null, $opts);
0
echo $before.'<a href="'.Config::current()->chyrp_url.'/admin/?action=delete_'.$name.'&id='.$this->id.'" title="Delete" class="'.($classes ? $classes." " : '').$name.'_delete_link delete_link" id="'.$name.'_delete_'.$this->id.'">'.$text.'</a>'.$after;