Subject: | unhelpful error message caused by error in relationship declaration |
In a Result class, ommiting the "foreign" or "self" keywords for the columns that form the relationship key pair leads to a very cryptic error message, for example:
__PACKAGE__->has_many(
"foos",
"MySchema::Result::Foo",
{ "foreign.bar_id" => "self.id" },
If the last line is typed as
{ "foreign.bar_id" => "id" },
the error message is just:
Odd number of elements in anonymous hash at XXX/DBIx/Class/ResultSource.pm line 1488
which makes it really hard to locate the problem.
It is caused by the DBIx::Class::ResultSource::__strip_relcond method, which just assumes that the column name must be preceeded by 'foreign' or 'self'
sub __strip_relcond {
+{
map
{ map { /^ (?:foreign|self) \. (\w+) $/x } ($_, $_[1]{$_}) }
keys %{$_[1]}
}
}
Maybe the solution would be to catch the error in
DBIx::Class::ResultSource::reverse_relationship_info
where __strip_relcond is called. Then the error message could point to the defective relationship.