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

Error on trying to sort records with row_order = null #73

Closed
stgeneral opened this issue Mar 28, 2014 · 4 comments
Closed

Error on trying to sort records with row_order = null #73

stgeneral opened this issue Mar 28, 2014 · 4 comments

Comments

@stgeneral
Copy link

class AddRowOrderToImages < ActiveRecord::Migration
  def change
    add_column :images, :row_order, :integer
  end
end

class Image < ActiveRecord::Base
  # ...
  include RankedModel
  ranks :row_order, with_same: [:attachable_id, :attachable_type]
end

@image.update_attribute :row_order_position, 0 
# raises NoMethodError (undefined method `-' for nil:NilClass):

I've solved it migrating to :null => false, :default => 0 for row_order column.

Solutions:

  • update README with example migration with specified :null => false, :default => 0
  • respect null value during row_order recalculations.
@mixonic
Copy link
Contributor

mixonic commented Mar 30, 2014

@stgeneral I believe the docs should just be updated, confirmed.

@glennr
Copy link

glennr commented Dec 20, 2018

This is at odds with this comment: #32 (comment)

The above linked fixed an issue for me whereby I had my column defaulting it to 0, but my ordering was screwing up on insertion (where no :row_order_position was supplied). Defaulting to null seems to have fixed the issue for me.

@brendon
Copy link
Owner

brendon commented Dec 20, 2018

I'm not sure if setting a default value for that column is supported from an ideological point of view unless you set it to the maximum or minimum value?

@brendon
Copy link
Owner

brendon commented Jun 4, 2024

Having a default column value is not allowed. We check for this now.

@brendon brendon closed this as completed Jun 4, 2024
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

4 participants