attr_accessor nil on assocation

I'll make this as simple as I can...

class MyClass < ActiveRecord::Base

  attr_accessor :date

  has_many :somethings

end

my_class = MyClass.find :first

my_class.date = Date.today
my_class.date # date object

my_class.somethings.first.my_class # my_class
my_class.somethings.first.my_class == my_class # true

my_class.somethings.first.my_class.date # nil

Any ideas?

I'll make this as simple as I can...

class MyClass < ActiveRecord::Base

attr_accessor :date

has_many :somethings

end

my_class = MyClass.find :first

my_class.date = Date.today
my_class.date # date object

my_class.somethings.first.my_class # my_class
my_class.somethings.first.my_class == my_class # true

my_class.somethings.first.my_class.date # nil

With activerecord there can be more than one instance in memory
representing the same database object, and this is what happens here
(association 'backlinks' are not preloaded for you - there's a fresh
database access). Since your date attribute isn't persisted to the
database at all, this is to be expected unfortunately.

Fred

Frederick Cheung wrote:

With activerecord there can be more than one instance in memory
representing the same database object, and this is what happens here
(association 'backlinks' are not preloaded for you - there's a fresh
database access). Since your date attribute isn't persisted to the
database at all, this is to be expected unfortunately.

Fred

Gotcha. Now I can stop pulling my hair out and find another path.

Thanks, Fred.