Jeff Ward
2006-Jun-08 04:52 UTC
[Rails] 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 acts_as_list :scope => :parent_id end And here is what happens when I create a new page: Mysql::Error: #42S22Unknown column ''pages_count'' in ''field list'': UPDATE pages SET pages_count = pages_count + 1 WHERE (id = 2) Any ideas why it''s not asking for "children_count"? Jeff
Francois Paul
2006-Jun-21 16:38 UTC
[Rails] counter_cache is not looking for children_count with acts_as_tree
hi Jeff, i''m noticing the same problem, have you by any chance figured it out? :franc Jeff Ward wrote:> 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 > acts_as_list :scope => :parent_id > end > > And here is what happens when I create a new page: > > Mysql::Error: #42S22Unknown column ''pages_count'' in ''field list'': > UPDATE pages SET pages_count = pages_count + 1 WHERE (id = 2) > > Any ideas why it''s not asking for "children_count"? > > Jeff > _______________________________________________ > Rails mailing list > Rails@lists.rubyonrails.org > http://lists.rubyonrails.org/mailman/listinfo/rails > > >
Francois Paul
2006-Jun-21 17:07 UTC
[Rails] counter_cache is not looking for children_count with acts_as_tree
ok, to answer my own question. from http://dev.rubyonrails.org/ticket/1576 >> 04/07/06 10:56:38: Modified by Frodo Larik I was also a little confused by this, by thinking it was the name of the table, but it isn''t. according to reflection.rb the name is made up like this: def counter_cache_column if options[:counter_cache] == true "#{active_record.name.underscore.pluralize}_count" elsif options[:counter_cache] options[:counter_cache] end end that means if you set :counter_cache => true it uses a pluralized version of the class name. If you set :counter_cache => "whatever_counts" it uses the "whatever_counts" column for counting. Hope it helps. >> Francois Paul wrote:> hi Jeff, > i''m noticing the same problem, have you by any chance figured it out? > > :franc > > Jeff Ward wrote: >> 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 >> acts_as_list :scope => :parent_id >> end >> >> And here is what happens when I create a new page: >> >> Mysql::Error: #42S22Unknown column ''pages_count'' in ''field list'': >> UPDATE pages SET pages_count = pages_count + 1 WHERE (id = 2) >> >> Any ideas why it''s not asking for "children_count"? >> >> Jeff >> _______________________________________________ >> Rails mailing list >> Rails@lists.rubyonrails.org >> http://lists.rubyonrails.org/mailman/listinfo/rails >> >> >> > > _______________________________________________ > Rails mailing list > Rails@lists.rubyonrails.org > http://lists.rubyonrails.org/mailman/listinfo/rails > > >
Possibly Parallel Threads
- acts_as_tree counter_cache behavior is different than API docs
- acts_as_tree wierdness with children.count and children.size
- Should counter_cache fields be saved in the database?
- acts_as_tree counter_cache
- Using set_primary_key breaks acts_as_tree with non-integer column