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

Relation::CASCADE

Hi all,

I have a model "Block", it has belongsTo relation to model "Image".

In relation definition i set virtual foreign key action to Relation::CASCADE. So, i delete block model and i expect, that image model will be deleted, but it will not.

I don't understand, how to delete relate models. Please Tell me how to do it. Thank you for your help.



7.9k
Accepted
answer

cascade applies on hasMany or hasManyToMany relations

everything below is pseudocode


Model Blocks
    belongsTo Image

Model Images
    hasMany Blocks, foreign key => Relation::CASCADE

block->delete() //deletes only specific block

image->delete() // deletes the image and all related blocks

Thanks, humugus, for your reply