3

I cannot seem to get counter_culture to work with a conditional counter cache. It is working perfectly with the normal counter cache. Certificate approving and disapproving increments and decrements as expected.

So in my db, for Packet, slip_count works, via packet.slips.size, but I cannot figure out how to get the conditional approved_count. I am getting:

NoMethodError: undefined method

for each way I try to reference, i.e. packet.slips.approved.size

Packet
class Packet < ActiveRecord::Base
  has_many :slips, :dependent => :destroy
  ...
end
Slip
class Slip < ActiveRecord::Base
  belongs_to :packet
  counter_culture :packet
  has_one :certificate
  ...
end
Certificate
class Certificate < ActiveRecord::Base
  belongs_to :slip
  counter_culture [:slip, :packet], :column_name => Proc.new {|model| model.approved? ? 'approved_count' : nil}
  ...
end
Tache
  • 495
  • 3
  • 9

0 Answers0