Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

validates error #49

Closed
venomizer opened this issue Aug 7, 2012 · 2 comments
Closed

validates error #49

venomizer opened this issue Aug 7, 2012 · 2 comments

Comments

@venomizer
Copy link

I don't know if it is an issue with acts_as_list or just my code but i ran into the problem that if i have a validates :uniqueness on the position column, an error would come up when creating a new list_item saying that the position was not unique. I removed the validation and my app works fine now but thought it might be worth mentioning.

@RichardBradley
Copy link

I had a similar problem -- my position column is marked as unique in the database, and the "move_lower" implementation causes unique constraint errors.

I was able to fix this with the following monkey patch (this doesn't fix all methods, e.g. "move_to_bottom" / "move_to_top" are still broken):

module ActiveRecord::Acts::List::InstanceMethods
  # See acts_as_list/active_record/acts/list.rb
  def move_lower
    return unless other = lower_item
    swap_position_with other
  end

  def move_higher
    return unless other = higher_item
    swap_position_with other
  end

  def swap_position_with other_item
    acts_as_list_class.transaction do
      other_position = other_item.send(position_column)
      other_item.update_attributes! position_column => -1
      self_position = send(position_column)
      update_attributes! position_column => other_position
      other_item.update_attributes! position_column => self_position
    end
  end
end

@swanandp
Copy link
Contributor

@venomizer @RichardBradley :

Closing this because this issue has been fixed in later pull requests. Can you please update your gems and let us know if it's still an issue?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants