PhalconPHP - 设置默认外键操作

PhalconPHP - set the default foreign key action

有没有一种方法可以定义在每个模型中使用的默认外键操作,这样我就不必像下面那样在每个模型中都定义它了?

$this->hasOne('id', '\Namespace', 'id', [
    'foreignKey' => [
        'action' => \Phalcon\Mvc\Model\Relation::ACTION_CASCADE
    ]
]);

覆盖 hasOne()。

class YourBaseModel extends \Phalcon\Mvc\Model {

    protected function hasOne($local, $remote_model, $remote_field, $options = null) {
        $options['foreignKey'] = [
            'action' => \Phalcon\Mvc\Model\Relation::ACTION_CASCADE
        ];

        parent::hasOne($local, $remote_model, $remote_field, $options);
    }

}

class YourModel extends YourBaseModel {

    public function initialize() {
        $this->hasOne('id', '\Namespace', 'id');
    }

}