#738 ✓resolved
Brian Terlson

dm-is-list position updates behave strangely when position is beyond list bounds

Reported by Brian Terlson | January 2nd, 2009 @ 01:10 PM | in 0.10.0

You can set the position attribute of a list item to be less than the specified starting position, but not more than the maximum position. Either direct positional updates should not be checked at all, or, ideally, both min and max bounds should be checked.

What's more, moving a list item other than the last item to the end of the list by specifying a position greater than the last element will break the list. It sets the moved item's position to be one greater than the largest position and also shifts the other list elements down, so you end up with a gap.

Example to demonstrate:


%w(rubygems dm-core dm-is-list).each{|r| require r }

DataMapper.setup(:default, 'sqlite3::memory:')

class Todo
  include DataMapper::Resource

  property :id, Serial

  is :list
end

Todo.auto_migrate!

@todo_1 = Todo.create
@todo_2 = Todo.create
@todo_3 = Todo.create

@todo_1.position = -1
@todo_1.save

Todo.all.inspect
# => "[#<Todo id=1 position=-1>, #<Todo id=2 position=2>, #<Todo id=3 position=3>]"

@todo_1.position = 100
@todo_1.save

Todo.all.inspect
"[#<Todo id=1 position=4>, #<Todo id=2 position=1>, #<Todo id=3 position=2>]"

Comments and changes to this ticket

Please Sign in or create a free account to add a new ticket.

With your very own profile, you can contribute to projects, track your activity, watch tickets, receive and update tickets through your email and much more.

New-ticket Create new ticket

Create your profile

Help contribute to this project by taking a few moments to create your personal profile. Create your profile »

Referenced by

Pages