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

deleteWithRelated only works with direct relations #69

Open
optmsp opened this issue Jan 2, 2022 · 0 comments
Open

deleteWithRelated only works with direct relations #69

optmsp opened this issue Jan 2, 2022 · 0 comments

Comments

@optmsp
Copy link

optmsp commented Jan 2, 2022

The method deleteWithRelated() only seems to work with direct relations.

So this works just fine:

parent -> child

If I $parent->deleteWithRelated() then both parent and child are soft deleted.

However, this fails:

parent -> child -> child_of_child

In this situation, only parent and child are soft deleted, while child_of_child is untouched.

The solution is to update yii2-relation-trait with the needed information:

class parent()...
{
    public function relationNames()
    {
        return [
            'child',
            'child_of_child',
        ];
    }
    
    public function getChildOfChilds()
    {
        return $this->hasMany(ChildOfChild::className(), ['child_id' => 'id'])->via('Childs');
    }
}

However, if I remove relationNames() in the class def and let deleteWithRelated real-time determine this, it doesn't soft delete child_of_child. (

)

Is this correct behaviour?

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

1 participant