Man, this is confusing...
I can make things work (sort of) by doing the following:
1. I keep the constraint on parent_id and set the root parent_id to null
instead of 0. (Just like with acts_as_tree)
2. I create the first record (from the console) which is the root:
<code>root = Model.create("attributes" =>
"attributes")</code>
3. Then I create the second record:
<code>child1 = Model.create("attributes" =>
"attributes")</code>
4. Then I set child1 as a child of the root:
<code>root.add_child(child1)</code>
5. Then I check the database and the lft and rgt values are not
correct. They show as:
<code>
id parent_id lft rgt
1 NULL 0 2
2 1 0 1
</code>
6. Obviously this is not correct, so I manually change the values in the
database to the following:
<code>
id parent_id lft rgt
1 NULL 1 4
2 1 2 3
</code>
7. Then I add all the children, grand children etc.....
<code>
subchild1 = Model.create("attributes" => "attributes")
child1.add_child(subchild1)
child2 = Model.create("attributes" => "attributes")
root.add_child(child2)
subchild2 = Model.create("attributes" => "attributes")
child2.add_child(subchild2)
etc...
</code>
All of the other children and grand children are created successfully
and the lft and rgt values are updated accordingly and correctly.
So, the question remains.....why can''t I create the first records
correctly? Also, how do I create additional roots and their children
without manually updating the lft and rgt values?
--
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
-~----------~----~----~----~------~----~------~--~---