We have moved our forum to GitHub Discussions. For questions about Phalcon v3/v4/v5 you can visit here and for Phalcon v6 here.

Delete related records after SoftDelete

Hello.

Sometimes I need delete related records after SoftDelete.

This code works fine:


$this->addBehavior(new SoftDelete(
            array(
                'field' => 'is_deleted',
                'value' => AuthUsers::DELETED
            )
        ));

But cascade delete dont work (when soft delete removed its work):


$this->hasMany(
            "au_uuid", "Repo\AuthUsersRoles",
            "aur_user_uuid",
            array(
                "foreignKey" => array(
                    'action' => Relation::ACTION_CASCADE
                )
            )
        );

Can somebody helps to me? Thanks.



8.1k

So the related rows should be actually deleted? (Not soft-deleted?) (Well, how that should behave should of course depend on the related Model configuration) Got it working? Seems to be a bug otherwise?

Yes they should be deleted(i think so) depends on model behavior. If there described delete cascade, then delete it. Of course there is can be behavior with soft delete.

At now, I don't use this feature.

Thanks.



8.1k
edited May '14

Ok, cool, thx for your reply. I just started working with this feaure, so I'll keep an eye out on the issue... ;-)

Phalcon doesn't take "soft delete" as a truely "delete", it's actually a update. So soft delete won't trigger any delete events, like beforeDelete() or afterDelete(). And it won't trigger cascade delete, too.

Sorry, my English is poor. I hope you understand what I mean.