brendon / acts_as_list

An ActiveRecord plugin for managing lists.
http://brendon.github.io/acts_as_list/
MIT License
2.04k stars 355 forks source link

Default Ordering Attribute when not ordering in associated model #316

Closed shaam48 closed 3 months ago

shaam48 commented 6 years ago

Model1.rb

belongs_to :model2, polymorphic: true, autosave: true
scope :ordered, -> { reorder(:position) }

Model2.rb

belongs_to :model1, polymorphic: true
acts_as_list scope: :model1
scope :ordered, -> { reorder(:position) }

Is it defaulting to ordering by :updated_at attribute?

brendon commented 6 years ago

Hi @shaam48, I don't quite understand your question, but the default order is database dependent and usually depends on insertion order unless you define an explicit ordering.

You might want to check your approach to polymorphic association because that doesn't look correct to me.

shaam48 commented 6 years ago

For some reason it is ordering it based on :updated_at attribute.

Ignore the polymorphic association made a mistake there.

brendon commented 6 years ago

Are you actually calling Model1.ordered? Also, ordered might be a reserved word, try another scope name :)

brendon commented 3 months ago

Closing due to inactivity.