Skip to content
Permalink
Browse files

Added example to README

  • Loading branch information...
dhoss committed Oct 9, 2014
1 parent f76c8f3 commit 75036b53e1b88c017971777065d3b961223de2a8
Showing with 28 additions and 1 deletion.
  1. +28 −1 README.md
@@ -9,7 +9,18 @@ treeify
Synopsis
========

1. Create your model
1. Create your migration

```
create_table :nodes do |t|
t.text :name
t.integer :parent_id
t.references :parent
end
add_index :nodes, [:parent_id, :id], :unique => true
```

2. Create your model

```
class Node < ActiveRecord::Base
@@ -19,6 +30,22 @@ class Node < ActiveRecord::Base
validates_uniqueness_of :name
validates_uniqueness_of :parent_id, :scope=> :id
end
```

3. Create a tree of stuff

```
parent = Node.create(name: "parent node")
child = parent.children.create(name: "child 1")
child2 = child.children.create(name: "child 2")
```

4. Retrieve tree of stuff

```
parent.descendent_tree
```

License

0 comments on commit 75036b5

Please sign in to comment.
You can’t perform that action at this time.