From 3918dc68c7cf7d6f7d2352f9aa4b68d4d02b7d6a Mon Sep 17 00:00:00 2001 From: Matt Jankowski Date: Thu, 7 Dec 2023 09:49:05 -0500 Subject: [PATCH] Use composite primary key for `PreviewCardsStatus` model (#28208) --- app/models/preview_cards_status.rb | 4 +--- app/models/status.rb | 4 +--- 2 files changed, 2 insertions(+), 6 deletions(-) diff --git a/app/models/preview_cards_status.rb b/app/models/preview_cards_status.rb index 341771e4d..214eec22e 100644 --- a/app/models/preview_cards_status.rb +++ b/app/models/preview_cards_status.rb @@ -9,9 +9,7 @@ # url :string # class PreviewCardsStatus < ApplicationRecord - # Composite primary keys are not properly supported in Rails. However, - # we shouldn't need this anyway... - self.primary_key = nil + self.primary_key = [:preview_card_id, :status_id] belongs_to :preview_card belongs_to :status diff --git a/app/models/status.rb b/app/models/status.rb index eb7159dc6..4bdadae06 100644 --- a/app/models/status.rb +++ b/app/models/status.rb @@ -82,8 +82,7 @@ class Status < ApplicationRecord has_and_belongs_to_many :tags - # Because of a composite primary key, the `dependent` option cannot be used on this association - has_one :preview_cards_status, inverse_of: :status # rubocop:disable Rails/HasManyOrHasOneDependent + has_one :preview_cards_status, inverse_of: :status, dependent: :delete has_one :notification, as: :activity, dependent: :destroy has_one :status_stat, inverse_of: :status, dependent: nil @@ -146,7 +145,6 @@ class Status < ApplicationRecord # The `prepend: true` option below ensures this runs before # the `dependent: destroy` callbacks remove relevant records before_destroy :unlink_from_conversations!, prepend: true - before_destroy :reset_preview_card! cache_associated :application, :media_attachments,