rails/rails — pull request #9443 by exviva (2013-02-26 16:03:37+00:00)
Title: Fix touching an invalid parent record for belongs_to

If the parent of a `belongs_to` record fails to be saved due to
validation errors, `touch` will be called on a new record, which causes
an exception (see https://github.com/rails/rails/pull/9320).

Example:

```ruby
class Owner < ActiveRecord::Base
validates_presence_of :name
end

class Pet < ActiveRecord::Base
belongs_to :owner, touch: true
end

pet = Pet.new(owner: Owner.new)

# Before, this line would raise ActiveRecord::ActiveRecordError
# "can not touch on a new record object"
pet.save
```