Hi, how do I get act_as_tree members to use the same object for their
parent?
For example at the moment I have:
tree_member = TreeMember.find(8)
sibling_tree_member = TreeMember.find(9)
tree_member.parent.id
=> 2
sibling_tree_member.parent.id
=> 2
tree_member.parent.object_id
=> 37862220
sibling_tree_member.parent.object_id
=> 37850860
Regards,
Ben
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
records.
Michael