Closed ysshir closed 3 years ago
class Model_Parent extends Orm\Model { protected static $_table_name = 'parent'; protected static $_primary_key = ['id']; protected static $_properties = [ 'id', 'name', ]; protected static $_has_many = [ 'children' => [ 'key_from' => 'id', 'model_to' => 'Model_Child', 'key_to' => 'parent_id', ], ]; }
class Model_Child extends Orm\Model { protected static $_table_name = 'child'; protected static $_primary_key = ['id']; protected static $_properties = [ 'id', 'parent_id', 'name', ]; protected static $_belongs_to = [ 'parent' => [ 'key_from' => 'parent_id', 'model_to' => 'Model_Parent', 'key_to' => 'id', ], ]; protected static $_has_many = [ 'grand_children' => [ 'key_from' => 'id', 'model_to' => 'Model_GrandChild', 'key_to' => 'child_id', ], ]; }
class Model_GrandChild extends Orm\Model { protected static $_table_name = 'grand_child'; protected static $_primary_key = ['id']; protected static $_properties = [ 'id', 'child_id', 'name', ]; protected static $_belongs_to = [ 'child' => [ 'key_from' => 'child_id', 'model_to' => 'Model_Child', 'key_to' => 'id', ], ]; }
try { $parent = \Model_Parent::query() ->related(['children', 'children.grand_children']) ->order_by('id') ->get(); } catch(Exception $e) { // sad :( }
Looks like a great fix, thanks!
tables..
parent
child
grand_child
Models...
problems