lundi 31 octobre 2016

Select where with timestamp values null not work

On laravel 5.3 with SqliteDriver

table cpjobs

...
$table->timestamp('created_at')->nullable(false);  // saved data unixtime
$table->timestamp('delayed_at')->nullable(true);  // saved data unixtime
...


| id  | delayed_at | start_at    |
|-----| ---------- | ----------- |
| 2   | null       | 1477912725  |
| 3   | 1478007928 | null        |
| 4   | null       | null        |   

if run on tinker

Cpjob::where('delayed_at', '>', '1478007902')->first();
    => App\Cpjob {#694
         id: "11",
         type: "backup",
         created_at: "1477911786",
         delayed_at: "1478007928",
       } 

But if run a complex for delayed_at > now and start_at null, return empty result, when must be return row with id 4

 Cpjob::where([['delayed_at', '<', '1477912725'],['start_at', null]])->first();
=> null

If get SQL generated...

>>> Cpjob::where([['delayed_at', '<', '1478007734'],['start_at', null]])->toSql();
=> "select * from "cpjobs" where ("delayed_at" < ? and "start_at" is null)"

I've tried several way for send time, unix timestamp, carbon, but all, produces same < ?



via Chebli Mohamed

Aucun commentaire:

Enregistrer un commentaire