Method: Sequel::Plugins::List::InstanceMethods#before_validation
- Defined in:
- lib/sequel/plugins/list.rb
#before_validation ⇒ Object
Set the value of the position_field to the maximum value plus 1 unless the position field already has a value. If the list is empty, the position will be set to the model’s top_of_list value.
190 191 192 193 194 195 196 197 |
# File 'lib/sequel/plugins/list.rb', line 190 def before_validation unless get_column_value(position_field) current_max = list_dataset.max(position_field) value = current_max.nil? ? model.top_of_list : current_max.to_i + 1 set_column_value("#{position_field}=", value) end super end |