FIX: ensure poll options keep their order

FIX: ensure poll options keep their order

From 606faa2ee5b1feda999982cf8c5bf3a02532b910 Mon Sep 17 00:00:00 2001
From: =?UTF-8?q?R=C3=A9gis=20Hanol?= <regis@hanol.fr>
Date: Fri, 23 Nov 2018 10:37:05 +0100
Subject: [PATCH] FIX: ensure poll options keep their order


diff --git a/plugins/poll/app/models/poll_option.rb b/plugins/poll/app/models/poll_option.rb
index f245d61..96a8d93 100644
--- a/plugins/poll/app/models/poll_option.rb
+++ b/plugins/poll/app/models/poll_option.rb
@@ -2,7 +2,7 @@ class PollOption < ActiveRecord::Base
   belongs_to :poll
   has_many :poll_votes, dependent: :delete_all
 
-  default_scope { order(created_at: :asc) }
+  default_scope { order(:id) }
 end
 
 # == Schema Information

GitHub

This commit has been mentioned on Discourse Meta. There might be relevant details there:

Note, my general pref is to avoid default_scope wherever possible. It introduces a lot of magic into the code.

In particular with this change it kind of masks the fact that you can not depend on ordering unless you are explicit about it for this one table. Additionally it gets complicated with all the order reorder stuff that rails has.

Is there any way we can just remove default_scope and add explicit scopes?

2 Likes

Sure, I’ll convert it to an explicit scope.

2 Likes

Is there any way we can just remove default_scope and add explicit scopes?

I added a default store on the relation in f7b7bc8abe6455ec8da543eb64d98d5d711d0773