I''m experiencing some unexpected weirdness with acts_as_tree. class Category < ActiveRecord::Base acts_as_tree has_many :variations end def variations # some code that returns the parent category variations if we have none end>> pc = Category.new >> pc.variations << "foo" >> pc.save >> cc = Category.new >> cc.parent = pc >> cc.saveSo far so good ...>> pc.variations .... ["foo"] >> cc.variations .... ["foo"]pc.variations.clear>> pc.variations ... [] <--- that''s expected >> cc.variations ... ["foo"] <-- UNEXPECTED!! >> cc = Category.find 2 >> cc.variations ... [] <-- again, expectedWhat''s going on here? The reference to pc and cc.parent are also not equal (before reloading even) but I guess that''s just how AR works. I''m used to Hibernate returning the same reference. Any suggestions or explanations? TIA, Sean --~--~---------~--~----~------------~-------~--~----~ 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 -~----------~----~----~----~------~----~------~--~---
> > What''s going on here? The reference to pc and cc.parent are also not > equal (before reloading even) but I guess that''s just how AR works. > I''m used to Hibernate returning the same reference. > > Any suggestions or explanations? > > TIA, > > Seanthere must be a problem with your variations method. doublecheck that area. -- 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 -~----------~----~----~----~------~----~------~--~---
Are you sure its not just that the reference to parent is out-dated? Maybe this is just a feature of ActiveRecord? If belongs_to type relationships are just copies of what''s in the database at the time that would explain it. It would also explain why re-retrieving the record produces the expected result. Sean On Oct 5, 7:33 am, Francis Sinson <rails-mailing-l...-ARtvInVfO7ksV2N9l4h3zg@public.gmane.org> wrote:> > What''s going on here? The reference to pc and cc.parent are also not > > equal (before reloading even) but I guess that''s just how AR works. > > I''m used to Hibernate returning the same reference. > > > Any suggestions or explanations? > > > TIA, > > > Sean > > there must be a problem with your variations method. doublecheck that > area. > -- > Posted viahttp://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 -~----------~----~----~----~------~----~------~--~---
schof wrote:> Are you sure its not just that the reference to parent is out-dated? > Maybe this is just a feature of ActiveRecord? If belongs_to type > relationships are just copies of what''s in the database at the time > that would explain it. It would also explain why re-retrieving the > record produces the expected result. > > Sean > > On Oct 5, 7:33 am, Francis Sinson <rails-mailing-l...-ARtvInVfO7ksV2N9l4h3zg@public.gmane.org>reload the parent of cc first. pc.variations.clear pc.variations ... [] <--- that''s expected cc.parent.reload cc.variations -- 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 -~----------~----~----~----~------~----~------~--~---