Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Filtered record being deleted on update #54

Open
kidzen opened this issue Feb 1, 2018 · 8 comments
Open

Filtered record being deleted on update #54

kidzen opened this issue Feb 1, 2018 · 8 comments

Comments

@kidzen
Copy link

kidzen commented Feb 1, 2018

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

@kidzen
Copy link
Author

kidzen commented Feb 1, 2018

closely related #48

@deadmantfa
Copy link

deadmantfa commented Feb 6, 2018

Hi I have been having the same issue. The problem is that it checks for ActiveQuery link parameter which return the relationship link but does not send the additional information such as on conditions and other conditions added to the relationship.
Check line 113 and code from line 172-181

@deadmantfa
Copy link

The $AQ variable has the conditions etc we can use that to add the delete query with more conditions based on the relationship condition

@kidzen
Copy link
Author

kidzen commented Feb 7, 2018

@deadmantfa so currently how did u handle this...

trait RelationTrait
{
    ....
    public function saveAll($skippedRelations = [],$ignoreList = [])
    {
    ....
                                            if($relModel->classname() === 'common\models\Branch'){
                                                $notEffective = ['not in', 'id', $ignoreList['common\models\Branch']];
                                                $query = ['and', ['company_id'=>12], ['not in', 'id', $notDeletedPK]];
                                                var_dump($relModel);
                                                array_push($query, $ignoreList);
                                                // var_dump($query);
                                            }
     }
}

@deadmantfa
Copy link

@kidzen Thanks for this I am trying a much better approach as i want to follow the code that's been there I am going to make a pull request on it soon.

@ragua
Copy link

ragua commented Mar 16, 2018

This is a really major issue deleting records with a parent update, this must be solved urgently or this soft won't be used anymore.

@strtob
Copy link

strtob commented Feb 7, 2019

Hi, is there any update? The software is really helpful and a great idea! Do anyone know a equal alterantive?

@synatree
Copy link

synatree commented Feb 4, 2022

The linked issue has a commit that solves the problem.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

5 participants