Guest

Untitled

By: a guest on Jan 28th, 2012  |  syntax: None  |  size: 0.85 KB  |  hits: 26  |  expires: Never
download  |  raw  |  embed  |  report abuse
Copied
  1. <?php defined('SYSPATH') or die('No direct script access.');
  2.  
  3. class ORM extends ORM_Core {
  4.  
  5.   protected $has_many_polymorphic = array();
  6.  
  7.   public function __get($column) {
  8.     if (isset($this->has_many_polymorphic[$column])) {
  9.       // one<>many polymorphic relationship
  10.       return $this->related[$column] = ORM::factory(inflector::singular($column))
  11.        ->where($this->polymorphic_field_id($column), $this->object[$this->primary_key])
  12.        ->where($this->polymorphic_field_object($column), inflector::singular($this->table_name))
  13.        ->find_all();
  14.     }
  15.     return parent::__get($column);
  16.   }
  17.  
  18.   protected function polymorphic_field_id($column) {
  19.     return $this->has_many_polymorphic[$column] .'_id';
  20.   }
  21.  
  22.   protected function polymorphic_field_object($column) {
  23.     return $this->has_many_polymorphic[$column] .'_type';
  24.   }
  25. }