Beefy Boxes and Bandwidth Generously Provided by pair Networks
Do you know where your variables are?
 
PerlMonks  

Help with Preventing cascading deletes in Class::DBI

by jira0004 (Monk)
on Aug 06, 2009 at 00:30 UTC ( [id://786262]=perlquestion: print w/replies, xml ) Need Help??

jira0004 has asked for the wisdom of the Perl Monks concerning the following question:

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
  • Comment on Help with Preventing cascading deletes in Class::DBI

Replies are listed 'Best First'.
Re: Help with Preventing cascading deletes in Class::DBI
by perrin (Chancellor) on Aug 06, 2009 at 13:46 UTC
    Your syntax looks ok. I suggest you either run your code in the debugger or add some warn statements to the Class::DBI code to see if it's really parsing your has_many correctly and putting the right thing in the cascade. I also suggest you ask on the Class::DBI list.
      Thanks for the suggestion perrin. which list do you suggest I send to? What is the email address or URL and I will drop them a line? --- Peter J.

Log In?
Username:
Password:

What's my password?
Create A New User
Domain Nodelet?
Node Status?
node history
Node Type: perlquestion [id://786262]
Approved by AnomalousMonk
help
Chatterbox?
and the web crawler heard nothing...

How do I use this?Last hourOther CB clients
Other Users?
Others meditating upon the Monastery: (4)
As of 2024-04-25 15:40 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    No recent polls found