Add Support for implicit_column_order to ActiveRecord::Batches finder methods

30 views
Skip to first unread message

Patrick Schmitz

unread,
Jul 13, 2019, 12:39:08 AM7/13/19
to Ruby on Rails: Core
With PR #34480, Tekin Suleyman added implicit_column_order for use with ordered finder methods. This support did not extend to ActiveRecord::Batches which enforces ordering on primary_key.  The same logic/reasoning introduced for implicit_column_order or defining an ordering column can be extended to ordering on ActiveRecord::Batches finder methods.

Branch with my proposed changes and tests

Tekin Süleyman

unread,
Aug 2, 2019, 4:23:08 AM8/2/19
to Rails Core Group
Hey Patrick,

The use case for `implicit_order_column` is only intended for configuring the behaviour of finder methods where an ordering is implied, i.e. `first` and `last`, and where the default of using the primary key to order results in unpredictable behaviour, i.e. when the PK is a UUID. It wasn't the intention that this be used as a way to define a default order on finder methods in general.

With regard to the batch finders specifically, enabling the order column to be overridden would open them up to subtle bugs and undesirable behaviour, particularly if the order column is one that isn’t guaranteed to be unique, e.g. the `created_at` timestamp. This could result in records being skipped or processed more than once.

Tekin

--
You received this message because you are subscribed to the Google Groups "Ruby on Rails: Core" group.
To unsubscribe from this group and stop receiving emails from it, send an email to rubyonrails-co...@googlegroups.com.
To post to this group, send email to rubyonra...@googlegroups.com.
Visit this group at https://groups.google.com/group/rubyonrails-core.
To view this discussion on the web visit https://groups.google.com/d/msgid/rubyonrails-core/0a2fb9dc-9975-4f32-8b0e-d8c865970908%40googlegroups.com.
For more options, visit https://groups.google.com/d/optout.

Reply all
Reply to author
Forward
0 new messages