Permalink
Browse files

fix insert_at for postgresql when position_column has non-null constr…

…aint
  • Loading branch information...
1 parent 261c4e7 commit 819c37df1a5cacb5990a5c2cb923531e570203f2 @rockrep rockrep committed with swanandp Jul 28, 2011
Showing with 9 additions and 1 deletion.
  1. +9 −1 lib/acts_as_list/active_record/acts/list.rb
@@ -273,10 +273,18 @@ def increment_positions_on_all_items
end
def insert_at_position(position)
- remove_from_list
+ store_at_0
increment_positions_on_lower_items(position)
self.update_attribute(position_column, position)
end
+
+ # used by insert_at_position instead of remove_from_list, as postgresql raises error if position_column has non-null constraint
+ def store_at_0
+ if in_list?
+ decrement_positions_on_lower_items
+ update_attribute(position_column, 0)
+ end
+ end
end
end
end

0 comments on commit 819c37d

Please sign in to comment.