I added a counter cache but can't get it to update. But I can update the parent - the Blog Post model by adding a new blog post - and I can update the child - Comments model - by adding a new comment. The counter cache is supposed to keep track of the total number of comments per blog post by auto-updating the blog_posts.comments_count f...
I am looking for a way to cache the number of each state. I have done counter caching before, but is there a way to create multiple counter_cache columns for each state and keep them updated or should I look elsewhere for caching these values.
aasm_column :state
aasm_initial_state :unopened
aasm_state :unopened
aasm_state :contacted
a...
I have a scenario where I want to have a question object and users can concurrently add answer objects to the question object.
The question object needs to maintain the answer count.
How can I do an implementation in Linq2Sql that transactionaly saves the answer object that the user submitted to the question and updates the incremented...
I'm using rspec for testing and hornsby scenarios for object graphs used in tests.
Is it good practice to initialize counter cache columns to 0 value instead of leaving them uninitialized (nil)? Or should i define default value in migrations that create those counter cache columns?
...
I rely on a counter cache value in an after_create hook of my model. However, my hook is called before the counter cache gets updated, thus breaking a computation.
Is there any way to force a counter cache "flush" so that I always see an up-to-date value in after_create?
...
Hi,
I have 3 models
Recommendation
Job
Qualification
Recommendation model has two fields as work_type and work_id(foreign key for job/qualification based on work_type as "J"/"Q")
I am facing problem in using counter_cache
I have done this in recommendation.rb
belongs_to :job , :counter_cache => true, :foreign_key => "work_id"
b...
Hi all,
I'm playing around with a fork of acts_as_taggable_on_steroids as a learning exercise. The version I'm looking at does some stuff I don't understand to calculate Tag counts. So I thought I'd do a version using PORC (Plain Old Rails Counters):
class Tagging < ActiveRecord::Base #:nodoc:
belongs_to :tag, :counter_cache => "tag...
I have a posts controller and a comments controller.
Post has many comments, and comments belong to Post.
The associate is set up with the counter_cache option turned on as such:
#Inside post.rb
has_many :comments
#Inside comment.rb
belongs_to :post, :counter_cache => true
I have a comments_count column in my posts table that is defa...
My Rails 3 app has 2 models and a third that's join table between them and their has_many relationships. Basically, User and Show are joined by SavedShow, allowing users to save a list of shows:
class Show < ActiveRecord::Base
has_many :saved_shows
has_many :users, :through => :saved_shows
end
class User < ActiveRecord::Base
has_...
I am wondering if the counter_cache would work in single table inheritance.
For these models:
class User
has_many :questions
end
class Question
belongs_to :user, :counter_cache => true
end
class SimpleQuestion < Question
end
class ComplexQuestion < Question
end
So will the following counters work?
create_table(:users) do |t|
...