[Dbix-class] constructing a query where fields are compared to each other

Karen Etheridge perl at froods.org
Thu Oct 17 00:39:12 GMT 2013

On Wed, Oct 16, 2013 at 08:13:34PM -0400, Rob Kinyon wrote:
> It's good you showed all the code because the extended comparison in a
> join relationship isn't possible. (It's one of ribasushi's many
> in-progress branches. Patches most definitely welcome here.)
> However, this is definitely possible in a search. You have to use the trapdoor.
>     ->search({ 1 => \"me.field_x - me.field_y" });
> That is a reference to a string.

A ha, so we drop down to literal SQL (via the scalar reference), but we
can't do that in a join because we can't jam the $args->{foreign_alias}
bits into the reference - it's then no longer literal SQL.

thanks!  looks like generating a new column to hold the value of the
arithmetic operation is indeed the right way to go (and I've already done
it, in the time it took for the mail to turn around). ;)

More information about the DBIx-Class mailing list