patrikw1's avatar

cannot retrieve model from :memory: database

Hello, i ran to the issue where i cannot retrieve eloquent model from a :memory: sqlite database inside my tests, thing is that i am using where query while interacting with JSON column, let me give you an example:

  1. After model is created and i get all models.. for example Tag::first(); i get following:
 "id" => 1
  "name" => array:1 [
      "en" => "test"
  ]
  "slug" => array:1 [
      "en" => "test"
  ]
  "type" => "questions"
  "order_column" => "1"
  "created_at" => "2018-05-09 18:40:59"
  "updated_at" => "2018-05-09 18:40:59"

so i know there is something persisted inside database.. In this case name and slug are json columns

  1. however when i use eloquent builder while using :memory: like so:
Tag::where('name->en', 'test')->first()

the result is null, nothing is retrieved from the database.

Thing is that this eloquent where query works perfectly in MySQL but in sqlite, i dont want to use mysql for my testsuite since i have around 650 tests and can quickly ran out of memory.

What can i do with it? my laravel homestead version is 6.0.. sqlite3 version is 3.22, is JSON1 extension allowed by default or what it causes? thanks

0 likes
1 reply
patrikw1's avatar

in case anyone wonder, i have used JSON_EXTRACT() to fix it for now

Tag::query()
     ->whereRaw("JSON_EXTRACT(name, '$.{$locale}') = '{$name}'")
     ->where('type', $type)
     ->first();

now gaves me eloquent model

1 like

Please or to participate in this conversation.