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.

Touch-ing with counter cache results in an erro

#5365

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.

Reported by Neil Middleton · August 12th, 2010 @ 03:56 PM

State: committed
Milestone: none
Assigned to: Santiago Pastorino Santiago Pastorino
Importance: Low

Activity

  1. José Valim
    José Valim
    • Importance changed from to Low

    Could you please add a failing test case to Rails test suite?

    August 12th, 2010 @ 04:59 PM

  2. Neil Middleton
    Neil Middleton

    Hi José,

    I would love to, but am not sure how, and therefore can't be sure that the test would be correct.

    N

    August 12th, 2010 @ 05:07 PM

  3. Mark Turner
    Mark Turner

    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.

    August 12th, 2010 @ 05:39 PM

  4. Neil Middleton
    Neil Middleton

    OK - had a stab at it - I've altered the models so that the issue causes some tests to fail.

    August 12th, 2010 @ 05:41 PM

  5. Mark Turner
    Mark Turner

    Here is a passing test using the correct syntax for touch.

    August 12th, 2010 @ 05:45 PM

  6. Neil Middleton
    Neil Middleton

    @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

    August 12th, 2010 @ 05:46 PM

  7. Mark Turner
    Mark Turner

    @Niel, you did find a corner case we didn't have a test for.

    August 12th, 2010 @ 05:46 PM

  8. Neil Middleton
    Neil Middleton

    @Mark - well, it's nice to make a rails contribution - no matter how small ;)

    August 12th, 2010 @ 05:48 PM

  9. Mark Turner
    Mark Turner
    • Tag changed from activerecord rails3, rails 3.0.0.rc, touch to activerecord rails3, rails 3.0.0.rc, patch, touch

    August 12th, 2010 @ 05:50 PM

  10. Mark Turner
    Mark Turner
    • Assigned user set to Santiago Pastorino

    August 13th, 2010 @ 11:51 PM

  11. Mark Turner
    Mark Turner
    • 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?

    August 16th, 2010 @ 11:28 PM

  12. Repository
    Repository
    • State changed from new to committed

    August 17th, 2010 @ 02:44 AM

  13. Repository
  14. Repository
  15. Repository