Skip to content

Filtered record being deleted on update #54

@kidzen

Description

@kidzen

Type 🐛

class Company () {
    ...
    public function getBranches()
    {
        return $this->hasMany(\common\models\Branch::className(), ['company_id' => 'id'])
        ->andWhere(['type' =< 10 ]);
    }
}

on update company record, those record with type 11 and above got deleted...

Suggestion :
add $ignoreClause parameter for saveAll() as additional

    public function saveAll($skippedRelations = [],$ignoreClause = [])
    {
        ....
        $query = ['and', $notDeletedFK, ['not in', $relPKAttr[0], $notDeletedPK]];
        array_push($query, $ignoreClause);           ....
        ...
        if (!empty($notDeletedPK)) {
            try {
                if ($isSoftDelete) {
                    $relModel->updateAll($this->_rt_softdelete, $query);
                } else {
                    $relModel->deleteAll($query);
                }
            } catch (IntegrityException $exc) {
                $this->addError($name, "Data can't be deleted because it's still used by another data.");
                $error = true;
            }
        }
        ....
    }

or adding list of effectiveIds only

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions