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.

objects created by find_or_create_by_ methods do not call after_initalize/after_create

#1901

class MyModel < ActiveRecord::Base

def after_initialize
  attrib1 = 'value'
end

end

class MyModelTest < ActiveSupport::TestCase

test "attrib should be value"
  test_model = MyModel.find_or_create_by_attrib2('I like cats')
  assert_equal 'value', test_model.attrib1
end

end

Reported by Adam S · February 7th, 2009 @ 01:20 AM

State: invalid
Milestone: 2.x
Assigned to: nobody
Importance: none

Activity

  1. Guillermo Álvarez
    Guillermo Álvarez

    Did you try to use

    self.attrib1 = 'value'

    February 7th, 2009 @ 07:12 PM

  2. Adam S
    Adam S

    Short answer, no.

    That will probably work. The confusing thing is that the method above worked some of the time (ie when i didn't use find_or_create_by ;).

    Ehhh... guess this ticket can be closed.

    February 9th, 2009 @ 01:56 AM

  3. CancelProfileIsBroken
    CancelProfileIsBroken
    • State changed from new to invalid

    March 8th, 2009 @ 01:08 PM