This project is archived and is in readonly mode.
AR callback not invoked on has_one child when saved through parent
Reported by Myron Marston | April 11th, 2009 @ 10:10 AM | in 2.x
See the attached test or the code below. This test passes in Rails 2.2.2 and fails in Rails 2.3.2.
require File.dirname(__FILE__) + '/../test_helper' ActiveRecord::Schema.define do create_table :parents, :force => true do |t| end create_table :children, :force => true do |t| t.integer :parent_id end end class InBeforeValidation < StandardError; end class Parent < ActiveRecord::Base has_one :child before_create do |model| model.build_child end end class Child < ActiveRecord::Base belongs_to :parent before_validation do |model| raise InBeforeValidation end end class HasOneCallbackTest < ActiveSupport::TestCase test "The child's before_validation callback is invoked when created and saved by the parent" do assert_raise InBeforeValidation do Parent.create end end end
Comments and changes to this ticket
-
Myron Marston April 11th, 2009 @ 11:11 PM
After searching through lighthouse some more, I can see that this is essentially the same issue, just with different effects. The patch in that ticket fixes this.
-
David Trasbo April 14th, 2010 @ 08:49 PM
- Assigned user set to Ryan Bigg
This can be marked as a duplicate.
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>