Skip to content

deleteWithRelated only works with direct relations #69

@optmsp

Description

@optmsp

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?

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