Proposal: Add alias_scope helper to ActiveRecord

Proposal: Introduce an alias_scope class method in ActiveRecord::Scoping::Named::ClassMethods that allows one scope to act as an alias for another.

Example Usage:

class Product < ApplicationRecord
  scope :active, -> { where(active: true) }
  alias_scope :enabled, :live, :published, :active
end

Product.active   # => returns all active products
Product.enabled  # => same as above
Product.live #  => same as above
Product.published #  => same as above

Benefits:

  • Reduces duplication for commonly aliased scopes.
  • Improves readability and maintainability of model code.
  • Keeps the API consistent with Rails’ existing scope DSL.

Implementation Notes:

  • Minimal change: just a helper method that delegates to an existing scope.
  • Fully backward-compatible.
  • Automated tests can verify that the alias behaves identically to the original scope.

Discussion Points:

  • Any concerns about adding this to ActiveRecord’s public API?

I’d love to hear feedback on whether this aligns with Rails conventions and if maintainers would be open to adding it if I opened a PR?

Would this be functionality different than:

class Product < ApplicationRecord
  scope :active, -> { where active: true }
  def self.enabled = active
  def self.live = active
  def self.published = active
end

For a lot of scope yours it a bit more compact. But would scopes generally be aliased just once so maybe the common case it’s not more compact. But on the plus side there is less magic. It’s clear it’s just a method that delegates.

It’s the same and it can also be expressed as:

class Product < ApplicationRecord
  scope :active, -> { where active: true }
  scope :enabled { active }
  scope :live { active }
  scope :published { active }
end

alias_scope is simply a more concise and elegant way to achieve this, much like alias_method is for methods.