Is there a way to define a default foreign key action to be used in every model so I don't have to keep defining it inside every model like below?
$this->hasOne('id', '\Namespace', 'id', [
'foreignKey' => [
'action' => \Phalcon\Mvc\Model\Relation::ACTION_CASCADE
]
]);
答案 0 :(得分:1)
覆盖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');
}
}