Skip to content

Instantly share code, notes, and snippets.

@metamn
Created March 5, 2010 11:20
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save metamn/322644 to your computer and use it in GitHub Desktop.
Save metamn/322644 to your computer and use it in GitHub Desktop.
>> Category.delete_all
=> 4
>> c = Category.create :name => "1"
=> #<Category id: 43, name: "1", description: nil, created_at: "2010-03-05 11:06:55", updated_at: "2010-03-05 11:06:55", ancestry: nil, ancestry_depth: 0>
>> d = Category.create :name => "11", :parent => c
=> #<Category id: 44, name: "11", description: nil, created_at: "2010-03-05 11:07:24", updated_at: "2010-03-05 11:07:24", ancestry: "43", ancestry_depth: 1>
>> e = Category.create :name => "111", :parent => d
=> #<Category id: nil, name: "111", description: nil, created_at: nil, updated_at: nil, ancestry: "43/44", ancestry_depth: 2>
>> d.children.create :name => "111"
=> #<Category id: nil, name: "111", description: nil, created_at: nil, updated_at: nil, ancestry: "43/44", ancestry_depth: 2>
>>
?>
?> ^C
>> Category.delete_all
=> 2
>> c = Category.create :name => "1"
=> #<Category id: 45, name: "1", description: nil, created_at: "2010-03-05 11:11:34", updated_at: "2010-03-05 11:11:34", ancestry: nil, ancestry_depth: 0>
>> d = Category.create :name => "11", :ancestry => 45
=> #<Category id: 46, name: "11", description: nil, created_at: "2010-03-05 11:11:52", updated_at: "2010-03-05 11:11:52", ancestry: 45, ancestry_depth: 1>
>> e = Category.create :name => "111", :ancestry => 46
=> #<Category id: 47, name: "111", description: nil, created_at: "2010-03-05 11:12:19", updated_at: "2010-03-05 11:12:19", ancestry: 46, ancestry_depth: 1>
>> c.children
=> [#<Category id: 46, name: "11", description: nil, created_at: "2010-03-05 11:11:52", updated_at: "2010-03-05 11:11:52", ancestry: "45", ancestry_depth: 1>]
>> d.children
=> []
>> e.parent
=> #<Category id: 46, name: "11", description: nil, created_at: "2010-03-05 11:11:52", updated_at: "2010-03-05 11:11:52", ancestry: "45", ancestry_depth: 1>
>> e.parent.children
=> []
>>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment