lib/para/orderable.rb in para-0.4.0 vs lib/para/orderable.rb in para-0.5.0

- old
+ new

@@ -2,14 +2,17 @@ module Orderable extend ActiveSupport::Concern included do scope :ordered, -> { order('position ASC') } - before_create :orederable_assign_position + before_create :orderable_assign_position end - def orederable_assign_position - last_resource = self.class.order('position DESC') + def orderable_assign_position + return if attribute_present?(:position) + + last_resource = self.class.unscoped + .order('position DESC') .where.not(position: nil) .select(:position) .first self.position = if last_resource && last_resource.position