how find ancestors (not direct parent) of record following model:
class model_category extends orm { protected $_belongs_to = array( 'parent' => array('model' => 'category', 'foreign_key' => 'category_id'), ); protected $_has_many = array( 'children' => array('model' => 'category', 'foreign_key' => 'category_id'), );
$category->parent->find() giving direct parent , when trying fetch parent of parent recursive function throws kohana_exception: method find() cannot called on loaded objects.
this occurs natural me guess there must easy way - i'm not sure if it's me or lack of documentation on orm relations - halp!
you should able recursive function or while loop
$current = $category; while ($current->parent->loaded()) { //save $current $current = $category->parent; }
Comments
Post a Comment