I have an ActiveRecord::Base
class which needs to have one field's value picked as the lowest integer available considering the records already in the database. This snippet does that, does it seem efficient to you? Can it be improved?
class Thing < ActiveRecord::Base
def initialize
special = 0
Thing.find(:all,:order=>"special ASC") do |s|
break if s.special.to_i != special
special += 1
end
super
write_attribute(:special,special)
end
end