Actually code:
class Model_Language extends ORM { protected $_has_many = array( 'supercategories' => array( 'model' => 'supercategory', 'foreign_key'=>'language_id', )); // get All Pages By Language Id public function PagesById($id) { // overload $this->_has_many = array( 'pages' => array( 'model' => 'page', 'foreign_key'=>'language_id', )); $language = ORM::factory('language',array('id'=>$id)); if ($language->loaded()) { $res = $language->pages->find_all(); $pages = array(); foreach ($res as $item) { $pages[] = array("id"=>$item->id, "name"=>$item->name, "url"=>$item->url, "content"=>$item->content); } return $pages; } else { return FALSE; } } }
And of course a mistake about this:
Kohana_Exception [ 0 ]: The pages property does not exist in the Model_Language class MODPATH\orm\classes\kohana\orm.php [ 621 ] 616 617 return $model->where($col, '=', $val); 618 } 619 else 620 { 621 throw new Kohana_Exception('The :property property does not exist in the :class class', 622 array(':property' => $column, ':class' => get_class($this))); 623 } 624 } 625 626 /**
It's just that sometimes I need a link with a table with pages, i.e. pages
, and sometimes with the supercategories supercategories
. These two tables are not interconnected at all, but the ancestor 1 is the languages
table. How, then, to do?