This project is archived and is in readonly mode.
Touch-ing with counter cache results in an erro
Reported by Neil Middleton | August 12th, 2010 @ 03:56 PM
We have two models, one of 'things' and one of 'likes'
The relationship is :
Thing
has_many :likes
Like
belongs_to :thing, :counter_cache => :like_count, :touch => :true
If I then create a like against a thing the attached stack is returned with:
NoMethodError: undefined method true=' for
#<Thing:0x2b2c49df9788>
Removing :touch => :true from the Likes model makes the error go away, but then leaves your Thing model with a stale timestamp which is a bad thing.
This worked in all previous Rails 3.0 beta's but now appears to have changed.
Comments and changes to this ticket
-
José Valim August 12th, 2010 @ 04:59 PM
- Importance changed from to Low
Could you please add a failing test case to Rails test suite?
-
Neil Middleton August 12th, 2010 @ 05:07 PM
Hi José,
I would love to, but am not sure how, and therefore can't be sure that the test would be correct.
N
-
Mark Turner August 12th, 2010 @ 05:39 PM
This isn't a bug. When you use a symbol with :touch it attempts to update an attribute with that same name. He just needs to use :touch => true to update the updated_at field.
-
Neil Middleton August 12th, 2010 @ 05:41 PM
OK - had a stab at it - I've altered the models so that the issue causes some tests to fail.
-
Neil Middleton August 12th, 2010 @ 05:46 PM
@Mark it seems you're correct. In my app this is now working as it should. However, I'm not sure how this was previously working prior to rails3.0.0.rc
-
Mark Turner August 12th, 2010 @ 05:46 PM
@Niel, you did find a corner case we didn't have a test for.
-
Neil Middleton August 12th, 2010 @ 05:48 PM
@Mark - well, it's nice to make a rails contribution - no matter how small ;)
-
Mark Turner August 12th, 2010 @ 05:50 PM
- Tag changed from activerecord rails3, rails 3.0.0.rc, touch to activerecord rails3, rails 3.0.0.rc, patch, touch
-
Mark Turner August 13th, 2010 @ 11:51 PM
- Assigned user set to Santiago Pastorino
-
Mark Turner August 16th, 2010 @ 11:28 PM
- Title changed from Touch-ing with counter cache results in an error to Touch-ing with counter cache results in an erro
Any word on the test patch I added?
-
Repository August 17th, 2010 @ 02:44 AM
- State changed from new to committed
(from [6177a0be96cebac129d0e20d2b5ec009a00fa56c]) added testcase for belongs_to with a counter_cache and touch
[#5365 state:committed]
Signed-off-by: Santiago Pastorino santiago@wyeworks.com
http://github.com/rails/rails/commit/6177a0be96cebac129d0e20d2b5ec0... -
Repository August 17th, 2010 @ 02:47 AM
(from [f1b33f7f22b7cddb7a80afbfa134a62600391b22]) Restore pet -> owner relationship to the previous state
[#5365] http://github.com/rails/rails/commit/f1b33f7f22b7cddb7a80afbfa134a6...
-
Repository August 17th, 2010 @ 02:48 AM
(from [6f478b06989ee10b63c9581b266b60bb946afd4f]) Restore pet -> owner relationship to the previous state
[#5365] http://github.com/rails/rails/commit/6f478b06989ee10b63c9581b266b60...
-
Repository August 17th, 2010 @ 02:48 AM
(from [fc43c62fc68bc6a75fd57c2da252ede00dd319ba]) added testcase for belongs_to with a counter_cache and touch
[#5365 state:committed]
Signed-off-by: Santiago Pastorino santiago@wyeworks.com
http://github.com/rails/rails/commit/fc43c62fc68bc6a75fd57c2da252ed...
Create your profile
Help contribute to this project by taking a few moments to create your personal profile. Create your profile »
<h2 style="font-size: 14px">Tickets have moved to Github</h2>
The new ticket tracker is available at <a href="https://github.com/rails/rails/issues">https://github.com/rails/rails/issues</a>
People watching this ticket
Attachments
Referenced by
- 5365 Touch-ing with counter cache results in an erro [#5365 state:committed]
- 5365 Touch-ing with counter cache results in an erro [#5365] http://github.com/rails/rails/commit/f1b33f7f22b...
- 5365 Touch-ing with counter cache results in an erro [#5365] http://github.com/rails/rails/commit/6f478b06989...
- 5365 Touch-ing with counter cache results in an erro [#5365 state:committed]