ruby - Query by two column version number in rails -
i have 2 columns called major , minor trying greater , less queries on. represent versions. version 2.1, 2 in major column , 1 minor column. how can these queries? avoid creating new column.
the issue if query model.where('major > ? , minor > ?', 3, 4)
, won't 4.1 or 5.2 because minor less 4.
i using rails 3.2 , ruby 1.9. also, versions don't complicated number.number (ex. 2.9 or 4.3) lets assume in style.
i think correct sql query follows:
major > :major -- check bigger major or (major = :major , minor > :minor) -- check within same major
you can use in activerecord right placeholder conditions, though should remove comments (the parts of line after --
).
example:
myproductwithversion.where('major > :major or (major = :major , minor > :minor)', major: 2, minor: 1)
Comments
Post a Comment