[Dbix-class] Fwd: might_have for dbix versions
Peter Rabbitson
rabbit+dbic at rabbit.us
Tue May 28 12:23:56 GMT 2013
On Tue, May 28, 2013 at 10:01:42AM +0800, lim weityug wrote:
> Hi,
>
>
>
> Our company is maintaining 2 versions of dbix class, which is version
> 0.08115 and 0.08195. We have an issue on defining the condition in
> might_have relationship. Before we have the new server (which is running
> dbix version 0.08195), our result file is like the following:
>
>
>
> __PACKAGE__->might_have(
>
> 'sample',
>
> 'Schema::Result::Sample',
>
> {
>
> 'foreign.pid' => 'self.pid and sample.wstart = 0',
>
> },
>
> );
>
>
>
> This works well for version 0.08115
It does not work "well" - it works by accident. You are asking DBIC to
look for a column named (literally) q{self.pid and sample.wstart = 0}.
It only works because you are not asking DBIC to quote your identifiers
(a bad practice in general).
> but it fail for version 0.08195
In newer versions relationships metadata is interrogated more closely,
and everything understandably fails.
>
> We can’t just upgrade our dbix class to latest version as this require
> intensive regression test on our application which is very huge effort and
> high risk. We’re trying to see if there is any way for having the codes to
> be run in both dbix versions.
This is a *really* poor way to handle a critical dependency of a
critical project. While DBIC has an unparallelled track record for
backwards compatibility, there are limits to any effort. As a result you
will find yourself hitting more and more situations just like this one,
and will inevitably end up with a paralyzed codebase. It is just a
matter of time under such a policy.
QED - there isn't really a practical way to support this invalid syntax
on newer DBIC versions. The "best" solution I can offer is for you to
define the relationship depending which DBIC version your server has
loaded.
Since DBIC version 0.08190 the proper way to define such relationships
is by using a coderef which returns the SQL::Abstract snippet you are
after:
https://metacpan.org/source/RIBASUSHI/DBIx-Class-0.08250/lib/DBIx/Class/Relationship/Base.pm#L128
Cheers and good luck - you will need it ;)
More information about the DBIx-Class
mailing list