File tree Expand file tree Collapse file tree 1 file changed +8
-1
lines changed Expand file tree Collapse file tree 1 file changed +8
-1
lines changed Original file line number Diff line number Diff line change @@ -6,7 +6,6 @@ class Bill < ApplicationRecord
6
6
has_one :bill_detail
7
7
has_one :government_legislation_notice
8
8
has_many :bill_summaries , dependent : :destroy
9
-
10
9
# 각 Bill이 여러 bill_summaries 중 유저에게 노출할 것을 빠르게 참조할 수 있도록 역정규화 컬럼(current_bill_summary_id)을 사용
11
10
belongs_to :current_bill_summary , class_name : "BillSummary" , optional : true
12
11
@@ -15,4 +14,12 @@ class Bill < ApplicationRecord
15
14
16
15
scope :by_title , -> ( query ) { where ( "lower(title) LIKE ?" , "%#{ query . downcase } %" ) if query . present? }
17
16
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
18
25
end
You can’t perform that action at this time.
0 commit comments