From 6be06a2ae48053a46d408d591180ac930a0b281b Mon Sep 17 00:00:00 2001 From: Benn Oshrin Date: Mon, 14 Jan 2019 14:53:05 -0500 Subject: [PATCH] Fix deletion dependencies (NOJIRA) --- app/src/Model/Table/AttributesTable.php | 3 ++- app/src/Model/Table/MatchgridsTable.php | 10 +++++++++- app/src/Model/Table/RulesTable.php | 3 ++- 3 files changed, 13 insertions(+), 3 deletions(-) diff --git a/app/src/Model/Table/AttributesTable.php b/app/src/Model/Table/AttributesTable.php index ce45bc4ff..ceb727485 100644 --- a/app/src/Model/Table/AttributesTable.php +++ b/app/src/Model/Table/AttributesTable.php @@ -51,7 +51,8 @@ public function initialize(array $config) { $this->belongsTo('AttributeGroups'); $this->belongsTo('Matchgrids'); //$this->belongsToMany('Rules', ['through' => 'RuleAttributes']); - $this->hasMany('RuleAttributes'); + $this->hasMany('RuleAttributes') + ->setDependent(true); $this->setDisplayField('name'); diff --git a/app/src/Model/Table/MatchgridsTable.php b/app/src/Model/Table/MatchgridsTable.php index 9b0606096..463ab52ab 100644 --- a/app/src/Model/Table/MatchgridsTable.php +++ b/app/src/Model/Table/MatchgridsTable.php @@ -54,15 +54,23 @@ public function initialize(array $config) { $this->addBehavior('Timestamp'); // Define associations + // Note that ->setDependent() is only really reliable to 1 level of association. + // since it uses deleteAll(). ->setCascadeCallbacks() loads associated data + // and can therefore reach lower levels of association. This is pretty poorly + // documented and explained. $this->hasMany('ApiUsers') ->setDependent(true); $this->hasMany('Attributes') - ->setDependent(true); + ->setDependent(true) + ->setCascadeCallbacks(true); $this->hasMany('AttributeGroups') ->setDependent(true); $this->hasMany('Permissions') ->setDependent(true); $this->hasMany('Rules') + ->setDependent(true) + ->setCascadeCallbacks(true); + $this->hasMany('SystemsOfRecord') ->setDependent(true); // "Convenience" associations to separate different rule confidence modes $this->hasMany('CanonicalRules', ['className' => 'Rules']) diff --git a/app/src/Model/Table/RulesTable.php b/app/src/Model/Table/RulesTable.php index 56f04eaa8..cb86d1564 100644 --- a/app/src/Model/Table/RulesTable.php +++ b/app/src/Model/Table/RulesTable.php @@ -52,7 +52,8 @@ public function initialize(array $config) { // Define associations $this->belongsTo('Matchgrids'); - $this->hasMany('RuleAttributes'); + $this->hasMany('RuleAttributes') + ->setDependent(true); $this->setDisplayField('name');