-
-
Notifications
You must be signed in to change notification settings - Fork 206
Closed
Labels
Type: BugThe issue has indentified a bugThe issue has indentified a bug
Description
I have a Model with a date field, where I applied serialization.
When running a simple query, it is working ok, but when I use sum('some field') on the Model, then date is not serialized.
Sample Code (to reproduce the issue)
MyModel
import { DateTime } from 'luxon'
import { column, BaseModel } from '@ioc:Adonis/Lucid/Orm'
export default class MyModel extends BaseModel {
@column({ isPrimary: true })
public id: number
@column.date({
serialize: (value) => value.toFormat('yyyy-LL-dd'),
})
public date: DateTime
@column()
public dataValue: number
}
Query
const result = await MyModel.query().select('date').sum('data_value').groupBy('date')
Expected outcome
{
"result": [
{
"date": "2021-01-01",
"sum(`data_value`)": 1030
},
{
"date": "2021-01-02",
"sum(`data_value`)": 1040
}
]
}
Actual outcome
{
"result": [
{
"date": "2021-01-01T00:00:00.000Z",
"sum(`data_value`)": 1030
},
{
"date": "2021-01-02T00:00:00.000Z",
"sum(`data_value`)": 1040
}
]
}
When I run a query without sum, it is working well:
const result = await MyModel.query().select('date').groupBy('date')
Outcome:
{
"result": [
{
"date": "2021-01-01"
},
{
"date": "2021-01-02"
}
]
}
Metadata
Metadata
Assignees
Labels
Type: BugThe issue has indentified a bugThe issue has indentified a bug