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

Default Ordering Attribute when not ordering in associated model #316

Closed
shaam48 opened this issue Jun 22, 2018 · 4 comments
Closed

Default Ordering Attribute when not ordering in associated model #316

shaam48 opened this issue Jun 22, 2018 · 4 comments

Comments

@shaam48
Copy link

shaam48 commented Jun 22, 2018

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
Copy link
Owner

brendon commented Jun 22, 2018

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
Copy link
Author

shaam48 commented Jun 22, 2018

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

Ignore the polymorphic association made a mistake there.

@brendon
Copy link
Owner

brendon commented Jun 23, 2018

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

@brendon
Copy link
Owner

brendon commented Jun 4, 2024

Closing due to inactivity.

@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

2 participants