Subject: | Optionally warn when a relationship is redefined [PATCH] |
We've been using Schema::Loader for years on a large postgresql database. Over the years
we've had to add manual relationships to the generated schema files because S:L was missing
them for various reasons (often because they weren't declared in the database itself yet).
Now our schema is more complete and S:L is better at finding relationships and is adding
them to the generated schema files. However, they're being silently overridden by the manual
relationships we added previously. The old manually added relationships are usually
incomplete and sometimes plain wrong.
The attached patch makes it easy to identify redefined relationships. It carps is a relationship
is redefined while DBIC_TRACE is set.
Some other env var or control mechanism could be used, I just picked DBIC_TRACE as an easy
option. (I'd be happy if warnings were the default and were silenced by adding an attribute
like is_redefintion=>1 to the new relationship definition.)
Subject: | dbix-class-rel-redef-warn.patch |
diff --git a/cpan-5.008/lib/perl5/DBIx/Class/ResultSource.pm b/cpan-5.008/lib/perl5/DBIx/Class/ResultSource.pm
index 075c331..4d6f199 100644
--- a/cpan-5.008/lib/perl5/DBIx/Class/ResultSource.pm
+++ b/cpan-5.008/lib/perl5/DBIx/Class/ResultSource.pm
@@ -1085,6 +1085,12 @@ sub add_relationship {
}
my %rels = %{ $self->_relationships };
+ if ($rels{$rel} && $ENV{DBIC_TRACE}) {
+ # warning is useful e.g. for large Schema::Loader generated schemas where
+ # relationships have been added manually and then later generated by
+ # Schema::Loader.
+ carp "$rel relationship redefined";
+ }
$rels{$rel} = { class => $f_source_name,
source => $f_source_name,
cond => $cond,