jeudi 9 juillet 2015

find in range, finding the range, within 1 query

There's a need to find upper and lower boundaries every time and then find elements within range.
How could that be done within 1 query?

As of now I've got 3, 4:

def min
  @relation.where(conditions).minimum
end

def max
  @relation.where(conditions).where(@arel[:position].gt(min)).minimum
end

def result
  @relation.where(position: (min...max))
end

and stuff like this does not work:

def result
  min = arel.project(conditions.and(arel[:position].minimum))
  max = arel.project(conditions.and(arel[:position].gt(min)).and(arel[:position].minimum))
  @relation.where(position: (min...max))
end

Aucun commentaire:

Enregistrer un commentaire