Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix touching an invalid parent record for belongs_to #9443

Merged
merged 1 commit into from Feb 26, 2013

Conversation

exviva
Copy link
Contributor

@exviva exviva commented Feb 26, 2013

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 #9320).

Example:

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

@rafaelfranca
Copy link
Member

Could you add a CHANGELOG entry?

@frodsan
Copy link
Contributor

frodsan commented Feb 26, 2013

Before:

$ rails c
Loading development environment (Rails 4.0.0.beta1)
>> Pet.new(owner: Owner.new).save
ActiveRecord::ActiveRecordError: can not touch on a new record object

After:

$ rails c
Loading development environment (Rails 4.0.0.beta1)
>> Pet.new(owner: Owner.new).save
# => true

👍

@exviva
Copy link
Contributor Author

exviva commented Feb 26, 2013

@rafaelfranca done

@rafaelfranca
Copy link
Member

needs a rebase

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 rails#9320).

Example:

    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
@exviva
Copy link
Contributor Author

exviva commented Feb 26, 2013

ugh...done @rafaelfranca :)

rafaelfranca added a commit that referenced this pull request Feb 26, 2013
Fix touching an invalid parent record for belongs_to
@rafaelfranca rafaelfranca merged commit fcf8d6e into rails:master Feb 26, 2013
@rafaelfranca
Copy link
Member

Thank you

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

3 participants