Forum: Ruby on Rails How do I get act_as_tree members to use the same object for

Announcement (2017-05-07): is now read-only since I unfortunately do not have the time to support and maintain the forum any more. Please see and for other Rails- und Ruby-related community platforms.
6a0f344b71aa8888799d4c51f4bab474?d=identicon&s=25 Ben Stephens (Guest)
on 2007-06-12 10:20
(Received via mailing list)
Hi, how do I get act_as_tree members to use the same object for their

For example at the moment I have:

tree_member = TreeMember.find(8)
sibling_tree_member = TreeMember.find(9)
=> 2
=> 2

=> 37862220

=> 37850860

588ab1c0a5610a7e160a3b101abb91e6?d=identicon&s=25 MichaelLatta (Guest)
on 2007-06-12 17:32
(Received via mailing list)
Rails does not guarantee that all reads of a row result in the same
Ruby object.  When you traverse a relationship it will re-read the row
if that object has not traversed that relationship previously.  In
your case the .parent relationship is being traversed from each child
object so you get 2 ruby objects for the same row in the database.  If
you find all rows with parent == nil and walk down the tree you may be
able to ensure that there is only one ruby object for each row.  But,
it may only mean that the children relationship is cached.  This is
the biggest downside of AR and other thin layer OR layers.  But, it
also has advantages in that you can work with record sets that are
distinct in purpose even though they happen to include the same

This topic is locked and can not be replied to.