I have the following model in Rails which manages a Diabetes Settings table:
class DiabetesSetting < ApplicationRecord
belongs_to :user
validates :bs_min, :bs_max, :bs_target, :correction_number, numericality: { only_integer: true }
validates :correction_insulin, numericality: true
validates :bs_min {less_than: :bs_max }
validates :bs_max {greater_than: :bs_min}
validates :bs_target {less_than: :bs_max}
end
My Question: Is something like this, to compare the fields of a database with each other to validate, that when a new setting is created, one value is higher or lower than the other, possible in Rails or do I have to write custom validation methods for this?
To clarify: bs_min is the mimmum value of a numerical range and bs_max the max value of a numerical range. They are both attributes inside the diabetes settings model. The Question is if I can compare these values like I did or if I have to write custom methods to validate
Thanks in advance for Your help