Search code examples
entity-relationshipphalcon

Phalcon Relationship between yourself?


I wrote a Foo class with Phalcon. The Foo Model is initialized like this.

 $this->hasMany('id', 'Foo', 'parent_id', ['alias'=> 'children']);

Foo class has parent_id which is realted to Foo id.

class Foo extends Model {

   public $id;

   public $parnet_id;

   public $name;

}

Then want to get list with children

$foo = Foo:find();

$children = $foo->children;

Now it returns very big object. I want get children which have a parent_id same as fetched foo.

What is wrong? Is it has some logic? Thanks in advance.


Solution

  • You are doing it right. Just when dumping Phalcon Model objects the whole DI gets printed, that's why you are confused. You can however iterate the children without any problems. Also try dumping like this:

    print_r($foo->children->toArray());
    

    This way you will see the children printed as array.