Skip to content

Commit

Permalink
Added example to README
Browse files Browse the repository at this point in the history
  • Loading branch information
dhoss committed Oct 9, 2014
1 parent f76c8f3 commit 75036b5
Showing 1 changed file with 28 additions and 1 deletion.
29 changes: 28 additions & 1 deletion README.md
Expand Up @@ -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
Expand All @@ -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
Expand Down

0 comments on commit 75036b5

Please sign in to comment.