From 8218a2a671517bfca3f5a30ff417cda6979c65e3 Mon Sep 17 00:00:00 2001 From: Matt Jankowski Date: Tue, 30 Jul 2024 16:56:09 -0400 Subject: [PATCH] Use arel order in account associations --- app/models/concerns/account/associations.rb | 2 +- app/models/status_pin.rb | 2 ++ 2 files changed, 3 insertions(+), 1 deletion(-) diff --git a/app/models/concerns/account/associations.rb b/app/models/concerns/account/associations.rb index 1c67b07e511..064486a4859 100644 --- a/app/models/concerns/account/associations.rb +++ b/app/models/concerns/account/associations.rb @@ -26,7 +26,7 @@ module Account::Associations # Pinned statuses has_many :status_pins, inverse_of: :account, dependent: :destroy - has_many :pinned_statuses, -> { reorder('status_pins.created_at DESC') }, through: :status_pins, class_name: 'Status', source: :status + has_many :pinned_statuses, -> { StatusPin.latest }, through: :status_pins, class_name: 'Status', source: :status # Endorsements has_many :account_pins, inverse_of: :account, dependent: :destroy diff --git a/app/models/status_pin.rb b/app/models/status_pin.rb index dae4a5b4e6b..3ddbc2023a1 100644 --- a/app/models/status_pin.rb +++ b/app/models/status_pin.rb @@ -17,6 +17,8 @@ class StatusPin < ApplicationRecord validates_with StatusPinValidator + scope :latest, -> { reorder(created_at: :desc) } + after_destroy :invalidate_cleanup_info def invalidate_cleanup_info