mardi 29 novembre 2016

strange laravel query builder behaviour with dashes

This:

$stockCodes = \DB::connection('sage_accounts')
->table('sales_order_items')
->select('stock_code')
->from('sales_order_items')
->orderBy('stock_code')
->distinct()->get();

returns any stock code with an RDxxx-xx-H7-xx stock code format, but that's the incorrect format. The correct format is RDxxx-Hx-xx-xx. That query doesn’t return stock codes in that format. Take, for example sales order line item 11649, which has stock code RD0448-H7-09-28. It is not returned with the rest of the stock codes, and this:

$stockCodes = \DB::connection('sage_accounts')
->table('sales_order_items')
->select('stock_code')
->from('sales_order_items')
->where('id', 11649)
->orderBy('stock_code')
->distinct()->get();

Returns an empty data set. While this:

select distinct `stock_code` from `sales_order_items` 
where `id` = 11649 order by `stock_code` asc

returns the correct data

Why will query builder not return items where the stock code is in format RDBxxxx-Hxx ?



via Chebli Mohamed

Aucun commentaire:

Enregistrer un commentaire