Skip to content
This repository was archived by the owner on Apr 17, 2018. It is now read-only.
This repository was archived by the owner on Apr 17, 2018. It is now read-only.

Avg returns 0.0 for empty table (dm-1.2.0) #15

@Ragmaanir

Description

@Ragmaanir

Hi,

when i do

MyModel.avg(:something)

i get 0.0 for an empty table (sqlite3, integer property). I think this is wrong and should return nil instead (SQL AVG returns null).
I guess this is caused by the to_f in:

def avg(property, value)
    property.primitive == ::Integer ? value.to_f : property.load(value)
end

in the dm-aggregates/adapters/dm-do-adapter.rb.

A quick workaround i use is to call MyModel.aggregate(:all.count, :something.sum) and compute the average myself.

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions