Solved thread

This post is marked as solved. If you think the information contained on this thread must be part of the official documentation, please contribute submitting a pull request to its repository.

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.



5.7k
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