Questions tagged [counter-cache]

129 questions
2
votes
2 answers

Skip rails counter_cache update

I have a model that uses rails' built-in counter_cache association to increment/decrement counts. I have a requirement wherein I need to disable this when I destroy the model for a specific situation. I have tried to do something like…
db_db
  • 21
  • 2
2
votes
1 answer

Setting up counter cache scale

My counter cache is locking the row under heavy load so I found wanelo/counter-cache gem which seems to be perfect for my problem but I can't set it up and it must be something really simple but I can't see…
Leticia Esperon
  • 2,499
  • 1
  • 18
  • 40
2
votes
1 answer

Change multiple counters in the same query with counter_culture

I have the following class with several counter_culture counters for the same association: class Book < ::ActiveRecord::Base belongs_to :user counter_culture :user counter_culture :user, column_name: Proc.new { |b| b.comedy? ?…
mrstif
  • 2,736
  • 2
  • 27
  • 28
2
votes
1 answer

CakePHP 3: CounterCache with BelongsToMany

I have a BelongsToMany association, my tables are PostsTable, TagsTable and PostsTagsTable. As explained here in the CakePHP book (associations), I have this fields: tags.id, tags.tag, tags.post_count posts_tags.id, posts_tags.tag_id,…
2
votes
1 answer

count columns is not automatically updated, have to run counter_culture_fix_counts to fix each time add new record

I'm using counter_culture to create survey applications the problem is each time I add citizen the count columns is not automatically update I have to go to console and run Citizen.counter_culture_fix_counts below is my model and controller for…
widjajayd
  • 6,090
  • 4
  • 30
  • 41
2
votes
1 answer

Rails 4, Impressionist and counter_cache

I have a Post model which I've made impressionable: is_impressionable :counter_cache => true, :column_name => :views I was thinking about, let's say once a month, clearing impressions older than a given period. Would this somehow reset the…
2
votes
1 answer

Mongoid 3.1.0 CounterCache doesn't work

I'm trying to use Mongoid CounterCache but it doesn't work. I tried to just use belongs_to :user, counter_cache: true But it returns Problem: Invalid option :counter_cache provided to relation :user. Summary: Mongoid checks the options that are…
Seif Sallam
  • 821
  • 2
  • 10
  • 30
2
votes
1 answer

Cakephp hasAndBelongsToMany with countercache?

Anyone know how to get countercache working on HABTM setup? - categories ;id, name, test_count - tests ; id, name - test_to_categories ; test_id, category_id
Tom
  • 3,717
  • 5
  • 26
  • 28
2
votes
2 answers

Rails counter_cache Balance

Currently I am calculating a users balance by def balance transactions.where('txn_type = ?', Transaction::DEPOSIT).sum(:amount) - transactions.where('txn_type = ?', Transaction::PURCHASE).sum(:amount) end I am running a query…
Kyle C
  • 4,077
  • 2
  • 31
  • 34
1
vote
1 answer

_changed? method when using counter_cache

I need to update attribute :average_rate when new comment is added. I have in comments.rb belongs_to :page, :counter_cache => true and in page.rb has_many :comments after_save :update_average_rate and update_average_rate method in page.rb …
Pavel
  • 3,900
  • 6
  • 32
  • 41
1
vote
1 answer

Rails :counter_cache is not triggering after_update callback

So, I have a Folder and a FolderItem models. UPDATE # == Schema Information # # Table name: folders # # id :integer not null, primary key # name :string(255) not null # parent_folder_id :integer # …
1
vote
1 answer

Rails counter_cache'd association being updated with update_attributes; counter_cache column not updated

I'm running a Rails 2.3.14 app that is using a counter_cache column, something similar to: Workshop belongs_to :group, :counter_cache => true Group has_many :workshops If I assign my workshop to a group directly, the counter cache is updated…
Matt Rogish
  • 24,435
  • 11
  • 76
  • 92
1
vote
1 answer

How can I cache a calculated attribute in Rails 3 similar to counter_cache?

I have an attribute that is a calculated value based data from various other models. I am looking for a slick way to cache that value similar to counter_cache but where the value is updated automatically via a custom function. I already have the…
Bob Benedict
  • 467
  • 1
  • 4
  • 10
1
vote
2 answers

How to use counter_cache in Rails when some conditions on the count column

I have some code here class group < ActiveRecord::Base has_many :memberships, :dependent => :destroy has_many :members, :through => :memberships, :source => :person :conditions => ['memberships.pending = ?…
Ye Ren
  • 11
  • 2
1
vote
1 answer

Rails 6.1.4 counter_cache issue

I develop simple app which has Issue and IssueStep models. I'm not sure if I missed something with counter_cache because it not works as expected for relation defined with custom name and class_name. issue.steps.size - fire count() in DB, why?…
mateo
  • 179
  • 13
1 2 3
8 9