On Wed, Dec 14, 2011 at 12:06, JavierQQ [email protected] wrote:
and the next values shouldn’t be in that range.
I discovered that I can do this…
validates :min_val, :uniqueness => { :scope => :group_id},
But I want to validate that the new min/max value is not in a already
saved record
Is there a rails way to do that?
If I understand rightly, what you want to do is to divide the space up
into non-overlapping ranges. Is that correct? If so, then you could
use a validator function that checks the new record against all saved
records to see if there is overlap. That would be rather inefficient,
though, so if you’re adding new Scales frequently, it could slow down
the system. If adding Scales is very rare, then remember the old
maxim: all algorithms are fast, for sufficiently small values of N.
Alternately, you could just forget about max and just record the min,
with the implied max being just below the min of the next group when
sorted by min. That would also ensure you have no holes, except below
the lowest min. However, that could be less efficient in usage
(finding the right range for a value) because you’d have to make sure
that not only is it above this min, but there are no higher mins it’s
below…
-Dave
–
LOOKING FOR WORK! What: Ruby (on/off Rails), Python, other modern
languages.
Where: Northern Virginia, Washington DC (near Orange Line), and remote
work.
See: davearonson.com (main) * codosaur.us (code) * dare2xl.com
(excellence).
Specialization is for insects. (Heinlein) - Have Pun, Will Babble!
(Aronson)