I know that destroy cascade
will work if prop开发者_如何学Pythoner relationships are setup in the models, but I want to know whether there is a way to destroy cascade
on-the-fly, without needing to have everything setup? Maybe something like model.destroy :cascade
?
Or am I limited to raw SQL in this case?
I haven't heard of way of doing it on the fly, but rather than using raw SQL try this:
AssociatedModel.destroy_all(:model_id => @model.id)
@model.destroy
精彩评论