Skip Menu |

This queue is for tickets about the DBIx-Class-ResultSet-RecursiveUpdate CPAN distribution.

Report information
The Basics
Id: 65561
Status: resolved
Worked: 1 hour (60 min)
Priority: 0/
Queue: DBIx-Class-ResultSet-RecursiveUpdate

People
Owner: abraxxa [...] cpan.org
Requestors: LUKAST [...] cpan.org
Cc:
AdminCc:

Bug Information
Severity: Important
Broken in: 0.21
Fixed in: 0.22



Subject: nullify related has_many objects fails due to wrong condition
As stated in the modules documentation, recursive_update should set the corresponding foreign keys (belonging to the related row) to NULL when updating has_many relations. Unfortunately, this will never happen, because the condition is not checked correctly. If recursive_update can nullify the corresponding columns in the related table, it sets $if_not_submitted = 'nullify'; but later checks: if($if_not_submitted eq 'set_to_null'){...} Because of this little mistake, related objects are NEVER removed from has_many-relations when using recursive_update.
Subject: recursiveupdate_hasmany_nullify.patch
405c405 < elsif ( $if_not_submitted eq 'set_to_null' ) { --- > elsif ( $if_not_submitted eq 'nullify' ) {
For me it works, please provide a failing test case.
Here is the test. I also added another patch, which changes "nullify" to "set_to_null" instead of changing "set_to_null" to "nullify". I noticed that the first patch made some of the old test fail, because they specified 'if_not_submitted => set_to_null' manualy when calling recursive_update. I guess thats the reason why you could not reproduce my failure. The failure only happens when the related ids can be set to null, and "if_not_submitted" is NOT set manually. On Tue Feb 08 12:42:30 2011, ABRAXXA wrote: Show quoted text
> For me it works, please provide a failing test case.
Subject: nullify.patch
--- lib/DBIx/Class/ResultSet/RecursiveUpdate.pm 2011-02-09 14:42:55.000000000 +0100 +++ lib/DBIx/Class/ResultSet/RecursiveUpdate.pm.patched 2011-02-09 14:42:37.000000000 +0100 @@ -332,7 +332,7 @@ ->{is_nullable}; } - $if_not_submitted = $all_fks_nullable ? 'nullify' : 'delete' + $if_not_submitted = $all_fks_nullable ? 'set_to_null' : 'delete' unless defined $if_not_submitted; #warn "\tNULLABLE: $all_fks_nullable ACTION: $if_not_submitted\n";
Subject: nullify_test.tar
Download nullify_test.tar
application/x-tar 10k

Message body not shown because it is not plain text.

I wonder where you have the attribute from, because it isn't included in the docs, intentionally! The attribute is left from pre 0.20 to not break old code but shouldn't be used in new code and therefore isn't documented. When DBIC will get the RU feature it won't have that attribute either. If you pass an empty arrayref or undef to a has_many accessor the related rows will be deleted. That's also the first line of the docs for has_many relationship treatment. Are you on irc? Would be easier to discuss your problem with it there.
I will be on irc (#dbix-class) in 15 Minutes. To clearify things: I am not using the 'if_not_submitted' parameter at all. It is set by recursive_update itself. Deleting related rows works fine, The problem only occurs if the related collumn are nullable, in which case the rows should not be deleted (as stated in the doc).