On Fri, Dec 16, 2011 at 10:22 AM, Dave Aronson < [email protected]> wrote:
> > 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 > > Yes I think is more a query problem than something of rails I've already made a validation that won't let a user to save this : - min_v : 10 - max_v : 1 That validation was easy :) , but (for example) what if I have this -min_v : 0 -max_v :10 another -min_v : 21 -max_v : 30 and then someone wants to save this - min_v : 8 - max_v :25 I have to do some validation about it, I found this http://stackoverflow.com/questions/5028612/reservation-type-system-w-validation-rails-3-0 def uniqueness_of_date_range errors.add(:start_date, "not available") unless Room.where("? >= start_date" AND ? <= end_date", start_date, start_date).count == 0 errors.add(:end_date, "not available") unless Room.where("? >= start_date" AND ? <= end_date", end_date, end_date).count == 0 end but ... is there a better way? Thanks Javier -- You received this message because you are subscribed to the Google Groups "Ruby on Rails: Talk" group. To post to this group, send email to [email protected]. To unsubscribe from this group, send email to [email protected]. For more options, visit this group at http://groups.google.com/group/rubyonrails-talk?hl=en.

