Beefy Boxes and Bandwidth Generously Provided by pair Networks
laziness, impatience, and hubris

comment on

( #3333=superdoc: print w/replies, xml ) Need Help??

I'm using 0.07017 of DBIx::Class::Schema::Loader, and I'm confused by its output for two tables with a FK relationship.

Here are excerpts of two related tables, List and Notification. Notification is a subtable of List, with a proper FK in the (Postgres) database, and it's defined as ON DELETE CASCADE in the DB. These snippets were from the files generated by ::Loader.

# from TT/Schema/ __PACKAGE__->has_many( "notification", "TT::Schema::Notification", { "foreign.listid" => "self.listid", "foreign.ltype" => "self.ltype" + }, { cascade_copy => 0, cascade_delete => 0 }, ); # from TT/Schema/ __PACKAGE__->belongs_to( "list", "TT::Schema::List", { listid => "listid", ltype => "ltype" }, { is_deferrable => 1, on_delete => "CASCADE", on_update => "CASCADE" + }, );

The DBIx::Class docs say

By default, DBIx::Class cascades deletes across has_many, has_one and might_have relationships. You can disable this behaviour on a per-relationship basis by supplying cascade_delete => 0 in the relationship attributes. The cascaded operations are performed after the requested delete, so if your database has a constraint on the relationship, it will have deleted/updated the related records or raised an exception before DBIx::Class gets to perform the cascaded operation.
which I take to mean that cascade_delete should be false if the database is going to take care of the deleting for us. In this case, it will, because there's a foreign key from notification up to list with ON DELETE CASCADE. But then why is on_delete=>'CASCADE'?

It seems to me that the cascade_delete in the should be set to 1, to match the on_delete => 'CASCADE' in the Or, that they should be 0 and undef, respectively. But I would think they should match.

Am I misunderstanding something? Or is DBIx::Class::Schema::Loader not building my schema correctly?


In reply to DBIx::Class::Schema::Loader and on_delete/cascade_delete by petdance

Use:  <p> text here (a paragraph) </p>
and:  <code> code here </code>
to format your post; it's "PerlMonks-approved HTML":

  • Posts are HTML formatted. Put <p> </p> tags around your paragraphs. Put <code> </code> tags around your code and data!
  • Titles consisting of a single word are discouraged, and in most cases are disallowed outright.
  • Read Where should I post X? if you're not absolutely sure you're posting in the right place.
  • Please read these before you post! —
  • Posts may use any of the Perl Monks Approved HTML tags:
    a, abbr, b, big, blockquote, br, caption, center, col, colgroup, dd, del, div, dl, dt, em, font, h1, h2, h3, h4, h5, h6, hr, i, ins, li, ol, p, pre, readmore, small, span, spoiler, strike, strong, sub, sup, table, tbody, td, tfoot, th, thead, tr, tt, u, ul, wbr
  • You may need to use entities for some characters, as follows. (Exception: Within code tags, you can put the characters literally.)
            For:     Use:
    & &amp;
    < &lt;
    > &gt;
    [ &#91;
    ] &#93;
  • Link using PerlMonks shortcuts! What shortcuts can I use for linking?
  • See Writeup Formatting Tips and other pages linked from there for more info.
  • Log In?

    What's my password?
    Create A New User
    and the web crawler heard nothing...

    How do I use this? | Other CB clients
    Other Users?
    Others surveying the Monastery: (6)
    As of 2021-04-23 18:39 GMT
    Find Nodes?
      Voting Booth?

      No recent polls found