I have this query in Laravel Eloquent:
$measures = Measure::groupBy('time')
->selectRaw('time, sum("delta") as sum_delta, sum("redistributed") as sum_redistr')
->where('operation_id', 'ACC0000001')
->where('time', '>', '2020-05-09 00:00')
->where('time', '<', '2020-05-10 00:00')
->where('source', 'source1')
->where('conso_prod', 'Conso')
->get()
When I debug using toSql()
function, and then I paste it into pgAdmin, I get the correct result.
select time, sum("delta") as sum_delta, sum("redistributed") as sum_redistr from "measures"
where "operation_id" = 'ACC0000001'
and "time" > '2020-05-09' and "time" < '2020-05-10' and "source" = 'source1' and "conso_prod" = 'Conso' group by "time"
And I have a result each 30m which is correct.
But when I use eloquent, I have the same amount of rows, but all the time
fields are the same:
"2020-05-09 00:00"
instead of incrementing.
I don't understand why ? I use PostgreSQL with TimescaleDB extension.
In my model, I had my time casted to date
instead of datetime
protected $casts = [
'time' => 'date'
];
I changed it to :
protected $casts = [
'time' => 'datetime'
];
And it worked.
I let it there if someones fails like me ! Thanks for your help anyway
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With