Hi all,

I'm trying to prevent a cascading delete in Class::DBI, but not having any luck. I have a has_many relationship in my Class::DBI definition that indicates another Class::DBI table class has a foreign key column that references the primary key of this one -- it's 1-to-many. I do not have a foreign key constraint in my SQL DDL (schema) so I know it isn't the DBMS that's doing the cascading delete so it has to be Class::DBI that is doing it.

I have the following in my package which is named Qf::CDBI::Trades::trades :

__PACKAGE__->has_many('trade_log' => q{Qf::CDBI::Trades::trade_log}, { cascade => 'None' } );

This should tell Class::DBI that one or more trade_log records reference a trade record. The { cascade => 'None' } should tell Class::DBI that when a trade record us deleted from the Trades table not to delete any referencing Trade_Log records.

However, it isn't working, the Trade_Log records are being deleted any way.

I do have other relationships in my package where I want cascading delete, like the following:

__PACKAGE__->has_many( 'trade_aliases' => q{Qf::CDBI::Trades::trade_aliases} => q{trade_id}, { cascade => 'Delete' } );

and the records are getting deleted from trade_aliases (which I want), but also from trade_log which I don't want. According to the Class::DBI documentation, the above should work for specifying cascading delete on a has_many relationship basis. However, it isn't working for me -- trade_log records and trade_alias records are getting deleted when I delete a trade. I want the trade_alias records deleted but not the trade_log records.

Does anyone have any ideas as to why I am getting cascading delete even though I have { cascade => 'None' } which according to the documentation should prevent it? Anyone know what I am doing wrong or missing? Anyone know how I can set up my Class::DBI relationships to cause trade_aliases to be deleted when a trade is deleted but prevent deletions of trade_logs?

Thanks,

Sincerely,

Peter Jirak
peter.jirak@gmail.com

In reply to Help with Preventing cascading deletes in Class::DBI by jira0004

Title:
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, details, 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, summary, 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.