Displaying 20 results from an estimated 10000 matches similar to: "Counter cache like plugin for sum"
2007 Aug 21
2
counter cache
Hi,
I have two models, employees and departments, and i am using
counter_cache to count the number of employees in a department.
This works great, but employees can change their departments, and the
counter cache does not get updated to reflect this.
Is their a built in way to do this, or do i have to implement my own
before_save hook
thanks
--~--~---------~--~----~------------~-------~--~----~
2006 Mar 11
1
HABTM 1.1 - counter cache?
Just wondering - will HABTM (or thru or whatever it''s called) in Rails
1.1 have a counter_cache, similar to belongs_to?
Joe
--
Posted via http://www.ruby-forum.com/.
2008 Jun 03
1
Custom counter cache
class Category
has_many :tracks
end
class Track
belongs_to :category, :counter_cache => true
named_scope :converted, :conditions => {:converted => true}
named_scope :active, :conditions => {:active => true}
end
I want to make custom counters for scoped associations, e.g:
category.converted_tracks_count
category.active_tracks_count
And when `track` changes its converted,
2006 Jul 11
1
counter_cache, has_many and belongs_to
I am a bit confused about counter_cache here. The API docs
http://api.rubyonrails.org/classes/ActiveRecord/Associations/ClassMethods.html
say that only the belongs_to association can take the :counter_cache
option. When I try to use it on a has_many I get an "unknown key(s):
counter_cache" error.
Why would this be the case? belongs_to means that this model has a
field with an id
2006 Apr 16
2
conditional updated_on update
Hi list,
I''ve got some counter_caches in a model. When these get incremented - say on
a page view - my updated_on column also gets updated. How can I
conditionally not update updated_on if just these counter_cache columns
change?
The problem with that is that I am using acts_as_versioned which clones the
record each time updated_on changes. I am successfully ignoring the
counter_cache
2007 Jun 01
2
Ferret FileNotFound error after adding counter_cache to mode
I have a model that I''ve been indexing and searching with ferret with no
problems.
I just added a counter_cache for some voting functionality to the same
model and now when I perform the voting fxn on an object from that
model, I get the FileNotFound error as it looks for a file named
"_1c_1.del" ...which breaks my voting function.
I tried killing the server and my index
2006 Jan 02
0
HABTM / Counter Cache
All,
Is it possible to use counter_cache w/ has_and_belongs_to_many?
Thanks,
EJC
2005 Dec 15
1
migration: counter cache & "reset_column_information"
To speed up
<%= @project.members_count %>
, I added a counter cache to the ''projects'' table with the migration
below:
def self.up
add_column "projects", "members_count", :string, :default => "0"
Project.reset_column_information
Project.find(:all).each do |p|
p.update_attribute :members_count , p.members.count
2006 Apr 07
2
errors.add_to_base
What are the limitations on using:
errors.add_to_base
to display errors in views?
I have tried for days to add errors from my object.rb and they never get
displayed.
class Keyword < ActiveRecord::Base
validates_presence_of(:name, :message => "Name is required.")
validates_uniqueness_of(:name, :message => "This name is already in
use. Please try
2006 Feb 03
2
acts_as_tree counter_cache behavior is different than API docs
Before I file a ticket, I''ll query ya''ll about this:
The API docs for acts_as_tree''s counter_cache is to create a database column
called "children_count" to hold the counter_cache. I have enabled this
option in my model. While writing tests I wrote a test for creating children
from the a parent:
message = @forum_message["parent"].find
child =
2006 Jun 08
2
counter_cache is not looking for children_count with acts_as_tree
Hi there, the acts_as_tree API says that I can set a counter cache and
that it will automatically increment the "children_count" column. I
did that but when I create a new page it asks for a "pages_count"
column instead.
Here is the relevant part of page.rb model:
class Page < ActiveRecord::Base
acts_as_tree :order => :position, :counter_cache => true
2006 Mar 24
6
Should counter_cache fields be saved in the database?
As far as I can tell, the counter_cache option on a belongs_to model
doesn''t actually save anything in the database. For example, I have
the following models:
class Parent < ActiveRecord::Base
has_many :children,
:conditions => "deleted_at IS NULL"
end
class Child < ActiveRecord::Base
belongs_to :parent, :counter_cache => true
end
With the following
2007 May 21
2
Rails'' fixtures suck! But what about something like this?
Sorry about the very long email, but this is a hairy topic that''s been
annoying me for some time and I decided to try to do something about.
Also, if you got this twice, I apologize too, but it didn''t seem to
have successfully gone out the first time.
Background:
----------
I''ve been dealing with Rails for about a year and a half now. I''ve
been using
2009 Jun 01
4
counter_cache is making a redundant SELECT before UPDATE
Hi,
I have the following code:
Message, belongs_to :topic, :counter_cache => true
topic = Topic.find_from_permalink(params[:id])
topic.messages.create(params[:message])
When the message gets created, then AR issues a supplemental SELECT to
retrieve the message''s topic and then updates its messages_count. Why is
that happening?
If I do it manually:
if
2006 Mar 12
2
counter_cache reference/tutorial
I''m trying to use counter_cache, but I''m not doing something right.
It is unreliable and I keep having to correct it manually. Is there a
good tutorial or reference on how to use it on-line? I have the AWDR
book, but I need something more complete.
TIA,
Jeffrey
2006 Mar 18
4
Accessing overridden method
I have two model classes:
class Item < ActiveRecord::Base
belongs_to :channel, :counter_cache => true
validates_presence_of :channel
end
class Channel < ActiveRecord::Base
has_many :items, :dependent => true
end
In the Channel controller I have variable channel.items, an Array of
Items. I would like to use the Array find method. However,
channel.items.find() is a Rails
2006 May 22
3
STI, HABTM & counter_cache
Hello world...
I have an interesting issue that the online docs aren''t helping me with.
In my app I have 4 models
Item < ActiveRecord
Deal < Item
Product < Item
Category < ActiveRecord
Item has_and_belongs_to_many :categories...
On each category record I''d like to maintain a product_count and deal_count
to increase performance. This doesn''t appear
2007 May 14
3
Counter Problem
Hi. I have a problem with counters in Rails. The situation looks like
this:
-3 simple models
class Forum < ActiveRecord::Base
has_many :posts
end
class Topic < ActiveRecord::Base
has_many :posts
end
class Post < ActiveRecord::Base
belongs_to :topic, :counter_cache => true
belongs_to :forum, :counter_cache => true
end
- In migrations i have declared
t.column :posts_count,
2006 Dec 06
2
validates_uniqueness_of where scope euqals created_by "magic" field
I have the following ActiveRecord objects:
class Recipe < ActiveRecord::Base
has_many :ratings, :dependent => true
. . .
end
class Rating < ActiveRecord::Base
validates_uniqueness_of :created_by, :scope => :recipe_id
belongs_to :recipe, :counter_cache => true
. . .
end
The created_by field on Rating is implemented as a "magic" field
similar to this:
2006 Mar 25
2
acts_as_tree wierdness with children.count and children.size
i am making a category tree and i iterate over the category using my
counter_cache however it would show a different number than what was
actually being represetned in the tree.
Here is an example
cat.children = [cat2, cat3]
puts cat.children.size 2
puts cat.children_count 2
cat4.parent_id = cat.id
cat4.save
puts cat.children.size