http://qs321.pair.com?node_id=954035


in reply to DBIx::Class::Schema::Loader and on_delete/cascade_delete

DBIx::Class::Schema::Loader is building your schema in a sensible manner.

If you delete a List, the database will correctly delete all of the associated Notifications. If you delete a Notification, cpan::DBIx::Class will correctly not delete the associated List. There is no need to delete Notifications in Perl given than the database already did it, and there is likewise no need to tell the database to not delete Lists, because it won't try to do that.

Note that it is more efficient to have on_delete => 'CASCADE' in the database rather than having to do a round trip through Perl to cascade deletes. However some users don't like it there because it makes it too easy to accidentally wipe all of your data when doing routine maintenance. I understand that making this optional is a feature request for a future version of DBIx::Class::Schema:::Loader.

Replies are listed 'Best First'.
Re^2: DBIx::Class::Schema::Loader and on_delete/cascade_delete
by petdance (Parson) on Feb 15, 2012 at 19:03 UTC

    Thanks, Ben. What confuses me is why they are set differently.

    The way I understand this is that cascade_delete => 0 tells DBIC that it's not necessary for DBIC to delete the notifications manually, because Postgres will have done it automatically. That makes sense.

    But then why is there the on_delete => "CASCADE" at the notification level? What does DBIC do with that bit of knowledge?

    xoxo,
    Andy