Lighthouse has a new layout. Prefer the old one? Return to the old layout, and switch back any time from the link at the top of each page.

This project is archived and is in readonly mode.

Namespaced models in belongs to with counter cache set

#1678

If a namespaced model is referenced in the belongs_to that has a counter_cache => true then the counter cache column name is not properly inferred from the class.

This is an issue during a reassign of the belongs_to association.


>> post = Web::Post.create
=> #<Web::Post id: 1, title: nil, comments_count: nil>
>> post.comments.create
=> #<Web::Comment id: 1, post_id: 1, comment: nil>
>> post.reload
=> #<Web::Post id: 1, title: nil, comments_count: 1>
>> comment = post.comments.first
=> #<Web::Comment id: 1, post_id: 1, comment: nil>
>> comment.post = nil
ActiveRecord::StatementInvalid: SQLite3::SQLException: no such column: web/comments_count: UPDATE "posts" SET "web/comments_count" = COALESCE("web/comments_count", 0) - 1 WHERE ("id" = 1) 

Reported by Adam · December 31st, 2008 @ 08:14 PM

State: resolved
Milestone: 2.x
Assigned to: nobody
Importance: none

Activity

  1. Adam
    Adam

    I just came across a similar issue [#1129 Namespaced models with Counter Cache] that was fixed and this ticket just fixes up the reassign case that was missed as the column name was set in two different places. This patch also moves it to one method.

    December 31st, 2008 @ 08:20 PM

  2. Repository
    Repository
    • State changed from new to resolved

    (from [3ca5a0f9fd7b7921bca970859da8637011b22dd1]) Ensure belongs_to association with a counter cache in name spaced model works [#1678 Namespaced models in belongs to with counter cache set state:resolved]

    Signed-off-by: Pratik Naik pratiknaik@gmail.com http://github.com/rails/rails/co...

    March 6th, 2009 @ 10:09 PM

  3. bingbing