RatkoR / laravel-crate.io

Crate.io driver for Laravel
MIT License
36 stars 12 forks source link

Cannot update ARRAY data types #3

Closed SpareShade closed 8 years ago

SpareShade commented 8 years ago

Hello and thank you for this handy library ...

I'm getting

ErrorException in helpers.php line 686:
preg_replace(): Parameter mismatch, pattern is a string while replacement is an array

where trying to use the DB facade for updating a table that contains 'array' data type.

ie.

$tags=['yellow', 'light'];
\DB::table('things')->update(['tags' => $tags])->where('id', 1);

gets you the above error:

in helpers.php line 686
at HandleExceptions->handleError('2', 'preg_replace(): Parameter mismatch, pattern is a string while replacement is an array', '/home/spare/projects/ebc-website/vendor/laravel/framework/src/Illuminate/Support/helpers.php', '686', array('search' => '\?', 'replace' => array(array('yellow', 'light')), 'subject' => 'update things set tags = ?', 'value' => array('yellow', 'light')))
at preg_replace('/\?/', array('yellow', 'light'), 'update things set tags = ?', '1') in helpers.php line 686
at str_replace_array('\?', array(array('yellow', 'light')), 'update things set tags = ?') in QueryException.php line 56
at QueryException->formatMessage('update things set tags = ?', array(array('yellow', 'light')), object(ErrorException)) in QueryException.php line 39
at QueryException->__construct('update things set tags = ?', array(array('yellow', 'light')), object(ErrorException)) in Connection.php line 653

Inserting 'array' data types works fine ...

RatkoR commented 8 years ago

Hi,

there was really an issue with updating array types. Can you test your code with just updated master branch? I added tests for this kind of updates and they are passing now, but would like to see if you're ok with it also.

Thx

SpareShade commented 8 years ago

Hey Ratko thats' tops !! yes it is working for me too, thank you! I was fooled by Laravel trying to mull out it's own QueryException that was throwing 'preg_replace(): Parameter mismatch' error. huh! thus obfuscating the crate's response ...

Thanks again!