I found this behavior while using acts_as_tree but it applies to all
models using has_many and belongs_to.
The problem is shown when trying to build a tree.
class Category < ActiveRecord::Base
acts_as_tree
end
root = Category.build("name" => "root")
child1 = root.children.build("name" => "child1")
subchild1 = child1.children.build("name" => "subchild1")
child1.root # => subchild1
This happens because when building a child1 the child1.parent is not set
to root. Thus child1.has_parent? is false.
Is this the designed behavior, or is it a bug?
Thanks,
Charles
--
Charles Dupont Computer System Analyst School of Medicine
Department of Biostatistics Vanderbilt University