cyx/ohm-contrib

sorting bug ?

Closed this issue · 1 comments

I have a class < Ohm::Model mixing in Ohm::Timestamps and Ohm::DataTypes with 'status' as an integer attribute.

I'm trying to find all entities with a status value and sort them by their updated_at timestamps.

Entity.find(:status => 2).sort(:by => :updated_at, :order => "DESC").map &:updated_at

The redis command it generates doesn't work

"sort" "Entity:indices:status:2" "BY" "updated_at" "DESC"

It should be

"sort" "Entity:indices:status:2" "BY" "Entity:*->updated_at" "DESC"

Is this an ohm / ohm-contrib bug ? Or Did I miss something ?

Hey @letronje, sort is the low level method, but there's also sort_by. In this case, you can accomplish the sorting in two ways:

# Using sort_by
Entity.find(:status => 2).sort_by(:updated_at, :order => "DESC")

# Using sort
Entity.find(:status => 2).sort(:by => "*->updated_at", :order => "DESC")

The first version, sort_by, is translated to the second version internally.