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? -- Posted via http://www.ruby-forum.com/. --~--~---------~--~----~------------~-------~--~----~ You received this message because you are subscribed to the Google Groups "Ruby on Rails: Talk" group. To post to this group, send email to rubyonrails-talk-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org To unsubscribe from this group, send email to rubyonrails-talk-unsubscribe-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org For more options, visit this group at http://groups.google.com/group/rubyonrails-talk?hl=en -~----------~----~----~----~------~----~------~--~---
On 28 Apr 2008, at 22:11, Daniel Waite wrote:> > 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> Any ideas? > -- > Posted via http://www.ruby-forum.com/. > > >--~--~---------~--~----~------------~-------~--~----~ You received this message because you are subscribed to the Google Groups "Ruby on Rails: Talk" group. To post to this group, send email to rubyonrails-talk-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org To unsubscribe from this group, send email to rubyonrails-talk-unsubscribe-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org For more options, visit this group at http://groups.google.com/group/rubyonrails-talk?hl=en -~----------~----~----~----~------~----~------~--~---
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. > > FredGotcha. Now I can stop pulling my hair out and find another path. Thanks, Fred. -- Posted via http://www.ruby-forum.com/. --~--~---------~--~----~------------~-------~--~----~ You received this message because you are subscribed to the Google Groups "Ruby on Rails: Talk" group. To post to this group, send email to rubyonrails-talk-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org To unsubscribe from this group, send email to rubyonrails-talk-unsubscribe-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org For more options, visit this group at http://groups.google.com/group/rubyonrails-talk?hl=en -~----------~----~----~----~------~----~------~--~---