D. Taylor Singletary
2006-Feb-03 18:33 UTC
[Rails] 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 = message.children.create( "member_id" => 1, "forum_id" => 1, "subject" => ''another subject'', "body" => "good grief.") This follows the the API docs pretty closely at http://ar.rubyonrails.com/classes/ActiveRecord/Acts/Tree/ClassMethods.html However, the test fails for this reason: 4) Error: test_proper_creation_of_message_reply(ForumMessageTest): ActiveRecord::StatementInvalid: PGError: ERROR: column "forum_messages_count" does not exist : UPDATE forum_message SET forum_messages_count = forum_messages_count + 1 WHERE (id = 1) The docs do not mention creating a table column based on the model name. Is this the now intended behavior? Where is it documented and can the name of the column be overridden? Thank you for any help. D. Taylor Singletary -------------- next part -------------- An HTML attachment was scrubbed... URL: http://wrath.rubyonrails.org/pipermail/rails/attachments/20060203/82d2c88b/attachment.html
Ezra Zygmuntowicz
2006-Feb-03 22:18 UTC
[Rails] acts_as_tree counter_cache behavior is different than API docs
On Feb 3, 2006, at 10:33 AM, D. Taylor Singletary wrote:> 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 = message.children.create( "member_id" => 1, "forum_id" > => 1, "subject" => ''another subject'', "body" => "good grief.") > > This follows the the API docs pretty closely at http:// > ar.rubyonrails.com/classes/ActiveRecord/Acts/Tree/ClassMethods.html > > However, the test fails for this reason: > > 4) Error: > test_proper_creation_of_message_reply(ForumMessageTest): > ActiveRecord::StatementInvalid: PGError: ERROR: column > "forum_messages_count" does not exist > : UPDATE forum_message SET forum_messages_count = > forum_messages_count + 1 WHERE (id = 1) > > The docs do not mention creating a table column based on the model > name. Is this the now intended behavior? > > Where is it documented and can the name of the column be overridden? > > Thank you for any help. > > D. Taylor Singletary > > _______________________________________________ > Rails mailing list > Rails@lists.rubyonrails.org > http://lists.rubyonrails.org/mailman/listinfo/railsD- I ran into the same problem using acts_as_tree to make a small forum I wrote. You do have to name the *_count column after the tablename you use it in for things to work correctly. Not sure if the docs are just wrong or what. Cheers -Ezra Zygmuntowicz Yakima Herald-Republic WebMaster http://yakimaherald.com 509-577-7732 ezra@yakima-herald.com
D. Taylor Singletary
2006-Feb-03 22:48 UTC
[Rails] acts_as_tree counter_cache behavior is different than API docs
Thanks for the response. I''ll go ahead and file a ticket to fix the documentation then. D. Taylor Singletary On 2/3/06, Ezra Zygmuntowicz <ezra@yakima-herald.com> wrote:> > > On Feb 3, 2006, at 10:33 AM, D. Taylor Singletary wrote: > > > 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 = message.children.create( "member_id" => 1, "forum_id" > > => 1, "subject" => ''another subject'', "body" => "good grief.") > > > > This follows the the API docs pretty closely at http:// > > ar.rubyonrails.com/classes/ActiveRecord/Acts/Tree/ClassMethods.html > > > > However, the test fails for this reason: > > > > 4) Error: > > test_proper_creation_of_message_reply(ForumMessageTest): > > ActiveRecord::StatementInvalid: PGError: ERROR: column > > "forum_messages_count" does not exist > > : UPDATE forum_message SET forum_messages_count > > forum_messages_count + 1 WHERE (id = 1) > > > > The docs do not mention creating a table column based on the model > > name. Is this the now intended behavior? > > > > Where is it documented and can the name of the column be overridden? > > > > Thank you for any help. > > > > D. Taylor Singletary > > > > _______________________________________________ > > Rails mailing list > > Rails@lists.rubyonrails.org > > http://lists.rubyonrails.org/mailman/listinfo/rails > > D- > > I ran into the same problem using acts_as_tree to make a small > forum > I wrote. You do have to name the *_count column after the tablename > you use it in for things to work correctly. Not sure if the docs are > just wrong or what. > > > Cheers > -Ezra Zygmuntowicz > Yakima Herald-Republic > WebMaster > http://yakimaherald.com > 509-577-7732 > ezra@yakima-herald.com > > > > _______________________________________________ > Rails mailing list > Rails@lists.rubyonrails.org > http://lists.rubyonrails.org/mailman/listinfo/rails >-------------- next part -------------- An HTML attachment was scrubbed... URL: http://wrath.rubyonrails.org/pipermail/rails/attachments/20060203/0031bf3e/attachment.html