similar to: Counter Problem

Displaying 20 results from an estimated 4000 matches similar to: "Counter Problem"

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 Apr 18
1
what happened to my increment_counter method?
this used to work for me. i started re-writing my little app and now it doesn''t work. here''s my models: class Company < ActiveRecord::Base has_many :people end class Person < ActiveRecord::Base belongs_to :Company, :counter_cache => true end then i go into my console and say: c = Company.find(:first) c.increment_counter and its all like "waaaaaaH"
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 Jun 21
6
Sort table by child row property?
I''m building a simple forum system which features a topics and a posts table. The topic model has a has_many association with the post model, i.e.: class Topic < ActiveRecord::Base { has_many :posts } class Post < ActiveRecord:Base { belongs_to :topic, :dependent => true } Now, I wish to sort the topics by the created_at property of the last post, but I can''t
2006 Jun 08
2
Activerecord Update syntax.
This what I have - sadly, it does not work :( . posts = {params[:topic][:forum_id] => { "posts_count" => "posts_count + @topic.posts_count"}, @topic.forum_id => { "posts_count" => "posts_count - @topic.posts_count" } } Forum.update(posts.keys, posts.values) It''s suppose to subtract the posts_count from topic, and add it and subtract
2006 Feb 27
0
Better counter_caches
Hey everybody, Rails currently offers ''belongs_to :counter_cache'', which is a very basic replacement for count triggers: ":counter_cache - caches the number of belonging objects on the associate class through use of increment_counter and decrement_counter. The counter cache is incremented when an object of this class is created and decremented when it?s destroyed. This
2007 Sep 12
1
Counter cache like plugin for sum
Hi list, Is there a plugin similar to counter_cache except for caching sums instead of counts? The reason I ask is for performance and convenience for reporting. --~--~---------~--~----~------------~-------~--~----~ You received this message because you are subscribed to the Google Groups "Ruby on Rails: Talk" group. To post to this group, send email to
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/.
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 Feb 28
0
Confusion with counter and single table inheritance
I''m having trouble getting the magical counter to work in a rails app with single table inheritance. following is the relevant code. thank you class declarations class Job < ActiveRecord::Base has_many :vents end class Vent < ActiveRecord::Base belongs_to :job, :counter_cache => true validates_numericality_of :width end class Rectangular < Vent
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
2005 Mar 01
0
acts_as_tree counter_cache
Hi List, I''m new to and hot on RoR. And I have a question regarding acts_as_tree and counter_cache. What methods actually update the counter_cache column? I''ve only really started the app so i''ve just got it set up so that I can select the parent node (from a list of nodes that exclude all descendants of the current node) with a radio buttoned list named and valued
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
2007 Apr 18
3
[PATCH 0/6] i386 virtualization patches, Set 3
This round attempts to conclude all of the LDT related cleanup with some finally nice looking LDT code, fixes for the UML build, a bugfix for really rather nasty kprobes problems, and the basic framework for an LDT test suite. It is really rather unfortunate that this code is so difficult to test, even with DOSemu and Wine, there are still very nasty corner cases here - anyone want an iret to
2007 Apr 18
3
[PATCH 0/6] i386 virtualization patches, Set 3
This round attempts to conclude all of the LDT related cleanup with some finally nice looking LDT code, fixes for the UML build, a bugfix for really rather nasty kprobes problems, and the basic framework for an LDT test suite. It is really rather unfortunate that this code is so difficult to test, even with DOSemu and Wine, there are still very nasty corner cases here - anyone want an iret to
2006 Jan 03
4
Would someone like to tell me why this code will not solve my problem? (it''s short)
I am building an invoicing system but cannot use the auto_increment field to determine the invoice number (because they are running 3 different companies off the one system. I need to find the last invoice number from any given company and then add 1 to it to get the next invoice number. BUT, there is a unique case on the very first invoice produced because there is no earlier invoice
2006 Oct 25
1
how to use increment_counter in model
Hi, Here''s my controller function: >>> def feed @chriss_monster = ChrissMonster.find(params[:id]) @chriss_monster.feed redirect_to :action => ''list'' end <<< Here''s my model: >>> class ChrissMonster < ActiveRecord::Base def feed ChrissMonster.increment_counter :eat, :id end end <<< When I call the
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