Dear phalcon community,
I need a help with this. I have a category table with such structure:
'id', 'name', 'parent_id'
The model:
class Category extends Model
{
public $id;
public $name;
public $parent_id;public function initialize() {
$this->hasMany("id", 'Category', "parent_id", ['alias' => 'children']);
$this->belongsTo("parent_id", 'Category', "id", ['alias' => 'parent']);
}public function getSource()
{
return 'category';
}public function getCategories($parameters = null)
{
return $this->getRelated('children', $parameters);
}}
I am trying to get all children of each of category in model with function getCategories. But unfortunately it shows error:
Model 'Category' could not be loaded
Can someone help me? How to make a self relation with parent_id?