Skip to content

Commit 493d5ba

Browse files
fix: 잘못 제거된 Bill.update_current_bill_summary 복구
from 767d844
1 parent f103a18 commit 493d5ba

File tree

1 file changed

+8
-1
lines changed

1 file changed

+8
-1
lines changed

app/models/bill.rb

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,6 @@ class Bill < ApplicationRecord
66
has_one :bill_detail
77
has_one :government_legislation_notice
88
has_many :bill_summaries, dependent: :destroy
9-
109
# 각 Bill이 여러 bill_summaries 중 유저에게 노출할 것을 빠르게 참조할 수 있도록 역정규화 컬럼(current_bill_summary_id)을 사용
1110
belongs_to :current_bill_summary, class_name: "BillSummary", optional: true
1211

@@ -15,4 +14,12 @@ class Bill < ApplicationRecord
1514

1615
scope :by_title, ->(query) { where("lower(title) LIKE ?", "%#{query.downcase}%") if query.present? }
1716
scope :by_bill_type, ->(bill_type) { where(bill_type: bill_type) if bill_type.present? }
17+
18+
# bill_summaries 추가/삭제 시 current_bill_summary 자동 관리
19+
def update_current_bill_summary!(new_summary = nil)
20+
if auto_update_current_summary?
21+
summary = new_summary || bill_summaries.order(created_at: :desc).first
22+
update_column(:current_bill_summary_id, summary&.id)
23+
end
24+
end
1825
end

0 commit comments

Comments
 (0)