모듈: Mongoid::Association::Referenced::CounterCache::ClassMethods
- 다음에 정의됨:
- lib/mongoid/association/referenced/counter_cache.rb
인스턴스 메서드 요약 접기
-
#Decrement_counter(counter_name, ID) ⇒ 객체
ID와 일치하는 항목에서 카운터 이름을 하나씩 줄입니다.
-
#증분 _카운터 (counter_name, ID) ⇒ 객체
ID와 일치하는 항목에서 카운터 이름을 하나씩 증가시킵니다.
-
#reset_counters(ID, *counters) ⇒ 객체
.count() 메서드를 사용하여 지정된 카운터를 재설정합니다. db에서 쿼리합니다.
-
#update_counters(ID, counters) ⇒ 객체
값 계수만큼 지정된 카운터를 업데이트합니다.
인스턴스 메서드 세부 정보
#Decrement_counter(counter_name, ID) ⇒ 객체
ID와 일치하는 항목에서 카운터 이름을 하나씩 줄입니다. 이 메서드는 counter_cache가 활성화된 경우 연결 콜백에 사용됩니다.
84 85 86 |
# 파일 'lib/mongoid/association/referenced/counter_cache.rb', 줄 84 def decrement_counter(counter_name, id) update_counters(id, counter_name.to_sym => -1) end |
#증분 _카운터 (counter_name, ID) ⇒ 객체
ID와 일치하는 항목에서 카운터 이름을 하나씩 증가시킵니다. 이 메서드는 counter_cache가 활성화된 경우 연결 콜백에 사용됩니다.
71 72 73 |
# 파일 'lib/mongoid/association/referenced/counter_cache.rb', 줄 71 def 증분_카운터(counter_name, id) update_counters(id, counter_name.to_sym => 1) end |
#reset_counters(ID, *counters) ⇒ 객체
.count() 메서드를 사용하여 지정된 카운터를 재설정합니다. db에서 쿼리합니다. 이 메서드는 카운터가 손상되었거나 새 카운터가 컬렉션에 추가된 경우에 유용합니다.
39 40 41 42 43 44 45 46 |
# 파일 'lib/mongoid/association/referenced/counter_cache.rb', 줄 39 def reset_counters(id, *카운터) 문서 = id.is_a?(문서) ? id : 찾기(id) 카운터.각 do |이름| Relation_association = 관계[이름] counter_name = Relation_association.inverse_association.counter_cache_column_name 문서.update_attribute(counter_name, 문서.send(이름).카운트) end end |
#update_counters(ID, counters) ⇒ 객체
값 계수만큼 지정된 카운터를 업데이트합니다. 원자적 $inc 명령을 사용합니다.
58 59 60 |
# 파일 'lib/mongoid/association/referenced/counter_cache.rb', 줄 58 def update_counters(id, 카운터) 위치(:_id => id).Inc(카운터) end |