We have moved our forum to GitHub Discussions. For questions about Phalcon v3/v4/v5 you can visit here and for Phalcon v6 here.

reduce hasMany relation / resultSets

Does anyone know if it is possible to reduce hasMany relations?

class MyModel extends Model
{
   ...
   public function initialize(){
        $this->hasMany("id","SomeChild","parentId",array('alias' => 'children' /* maybe somthing like: "active = 1" */ ));
   }

   // or 

   public function getActiveChildren(){
        return $this->children->where("active = 1");
   }

}


9.2k
edited Apr '14

The first approach is not supported yet. :( Maybe the


public function getActiveChildren(){
    return $this->children->where("active = 1");
}

somehow?

You can already do:

$MyModel->getChildren(['conditions'=>'active = 1']);

But if you don't want to duplicate those conditions everwhere:

public function getActiveChildren(){
    return $this->getChildren(['conditions'=>'active = 1']);
}