
Untitled
By: a guest on Jan 28th, 2012 | syntax:
None | size: 0.85 KB | hits: 26 | expires: Never
<?php defined('SYSPATH') or die('No direct script access.');
class ORM extends ORM_Core {
protected $has_many_polymorphic = array();
public function __get($column) {
if (isset($this->has_many_polymorphic[$column])) {
// one<>many polymorphic relationship
return $this->related[$column] = ORM::factory(inflector::singular($column))
->where($this->polymorphic_field_id($column), $this->object[$this->primary_key])
->where($this->polymorphic_field_object($column), inflector::singular($this->table_name))
->find_all();
}
return parent::__get($column);
}
protected function polymorphic_field_id($column) {
return $this->has_many_polymorphic[$column] .'_id';
}
protected function polymorphic_field_object($column) {
return $this->has_many_polymorphic[$column] .'_type';
}
}