Skip to content

Commit

Permalink
Added onCondition and where condition for the FK delete queries
Browse files Browse the repository at this point in the history
  • Loading branch information
deadmantfa committed Feb 8, 2018
1 parent 8149499 commit f4ef3b4
Showing 1 changed file with 18 additions and 0 deletions.
18 changes: 18 additions & 0 deletions RelationTrait.php
Original file line number Diff line number Diff line change
Expand Up @@ -178,6 +178,14 @@ public function saveAll($skippedRelations = [])
$notDeletedFK = [];
$relPKAttr = ($AQ->multiple) ? $records[0]->primaryKey() : $records->primaryKey();
$isManyMany = (count($relPKAttr) > 1);
$conditions = [];
if (!empty($AQ->on)) {
$conditions[] = $AQ->on;
}

if (!empty($AQ->where)) {
$conditions[] = $AQ->where;
}
if ($AQ->multiple) {
/* @var $relModel ActiveRecord */
foreach ($records as $index => $relModel) {
Expand Down Expand Up @@ -209,6 +217,11 @@ public function saveAll($skippedRelations = [])
$notIn = ['not in', $attr, $value];
array_push($query, $notIn);
}
if (!empty($conditions)) {
foreach ($conditions as $condition) {
array_push($query, $condition);
}
}
try {
if ($isSoftDelete) {
$relModel->updateAll($this->_rt_softdelete, $query);
Expand All @@ -222,6 +235,11 @@ public function saveAll($skippedRelations = [])
} else {
// Has Many
$query = ['and', $notDeletedFK, ['not in', $relPKAttr[0], $notDeletedPK]];
if (!empty($conditions)) {
foreach ($conditions as $condition) {
array_push($query, $condition);
}
}
if (!empty($notDeletedPK)) {
try {
if ($isSoftDelete) {
Expand Down

0 comments on commit f4ef3b4

Please sign in to comment.