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
|
|---|
| 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 | |
by jira0004 (Monk) on Aug 06, 2009 at 14:37 UTC | |
by perrin (Chancellor) on Aug 06, 2009 at 16:04 UTC |