Skip to content

Commit

Permalink
Fix deletion dependencies (NOJIRA)
Browse files Browse the repository at this point in the history
  • Loading branch information
Benn Oshrin committed Jan 14, 2019
1 parent 5693b8c commit 6be06a2
Show file tree
Hide file tree
Showing 3 changed files with 13 additions and 3 deletions.
3 changes: 2 additions & 1 deletion app/src/Model/Table/AttributesTable.php
Original file line number Diff line number Diff line change
Expand Up @@ -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');

Expand Down
10 changes: 9 additions & 1 deletion app/src/Model/Table/MatchgridsTable.php
Original file line number Diff line number Diff line change
Expand Up @@ -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'])
Expand Down
3 changes: 2 additions & 1 deletion app/src/Model/Table/RulesTable.php
Original file line number Diff line number Diff line change
Expand Up @@ -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');

Expand Down

0 comments on commit 6be06a2

Please sign in to comment.