Phalcon 模型与附加条件具有多对多关系

Phalcon model hasManyToMany relation with additional condition

是否可以选择向 Phalcon 向导函数 hasManyToMany 添加附加条件?我检查了 phalcon docs 但它们没有列出 hasManyToMany 的所有可能选项(仅列出了别名和 foreginKey)。 如果这不能用 hasManyToMany 完成是否有任何其他可用的 Phalcon 选项 - 例如。检索所有然后过滤某些模型加载事件?

简单示例: 我有 3 个 table 组、关系和用户,并且想使用关系 table 在用户模型中创建两个属性 - active_groups 和 active_groups.

代码:

class GroupModel extends Model {
    public $id;    
    public $name;
}

class RelationModel extends Model {
    public $id;    
    public $related_id_one;
    public $related_id_two;
    public $active;
}

class UserModel extends Model {

    public function initialize() {

        $this->hasManyToMany(
            "id",
            "RelationModel",
            "related_id_one",
            "related_id_two",
            "GroupModel",
            "id",
            array(  'alias' => 'active_groups', 
                    'conditions' => 'RelationModel.active = true')
        );

        $this->hasManyToMany(
            "id",
            "RelationModel",
            "related_id_one",
            "related_id_two",
            "GroupModel",
            "id",
            array(  'alias' => 'inactive_groups', 
                    'conditions' => 'RelationModel.active = false')
        );
    }
}

谢谢!

你也可以这样做。顺便说一句,不能完全确定这段代码是否能正常运行,但希望你明白了。

我不知道 phalcon 是否有条件/where 选项

class GroupModel extends Model {
    public $id;    
    public $name;
}

class RelationModel extends Model {
    public $id;    
    public $related_id_one;
    public $related_id_two;
    public $active;
}

class UserModel extends Model {

    public function initialize() {

        $this->hasManyToMany(
            "id",
            "RelationModel",
            "related_id_one",
            "related_id_two",
            "GroupModel",
            "id",
            array(  'alias' => 'groups')
        );

    }

    public function getActiveGroups() {
      return $this->getGroups('RelationModel.active = true');
    }

    public function getInactiveGroups() {
      return $this->getGroups('RelationModel.inactive = false');
    }
}