[Dbix-class] +select problem with 0.7006
Ronald J Kimball
rkimball+dbixclass at pangeamedia.com
Thu Jun 7 14:22:27 GMT 2007
Will Hawes wrote:
>> From the docs and a quick chat on IRC I understand that the following:
>
> package My::Schema::Order_Product;
> ...
> __PACKAGE__->table('order_product');
> __PACKAGE__->add_columns(qw/ id product quantity unitprice /);
>
> ...
>
> my $rs = $c->model('Order_Product')->search(
> {},
> {
> +select => ['quantity * unitprice'],
> +as => ['line_total']
> }
> );
>
> should cause DBIC to generate something like:
>
> SELECT id, product, quantity, unitprice, quantity * unitprice FROM
> order_product me
>
> It's only giving me the following though:
>
> SELECT quantity * unitprice FROM order_product me
>
> The only way I can get the other columns is to add them manually using
> the "select" attribute.
>
> What have I done wrong here?
You need to put quotes around +select and +as:
my $rs = $c->model('Order_Product')->search(
{},
{
'+select' => ['quantity * unitprice'],
'+as' => ['line_total']
}
);
Otherwise, the + is a unary plus, which is basically a no-op.
{ +select => [] } is the same as { select => [] }.
Ronald
More information about the Dbix-class
mailing list