Skip to content

Commit

Permalink
Add Readme
Browse files Browse the repository at this point in the history
  • Loading branch information
StephaneRob committed Jul 14, 2017
1 parent dbcf9f2 commit da39968
Show file tree
Hide file tree
Showing 3 changed files with 62 additions and 4 deletions.
File renamed without changes.
65 changes: 61 additions & 4 deletions README.md
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
# Ancestry

**TODO: Add description**
_WIP_

## Installation

Expand All @@ -13,7 +13,64 @@ def deps do
end
```

Documentation can be generated with [ExDoc](https://github.com/elixir-lang/ex_doc)
and published on [HexDocs](https://hexdocs.pm). Once published, the docs can
be found at [https://hexdocs.pm/ancestry](https://hexdocs.pm/ancestry).
### Usage
Add an `ancestry` string field in your model

```bash
mix ecto.gen.migration add_ancestry_to_<model>
```

Add index to migration

```elixir
defmodule Migration do
use Ecto.Migration

def change do
create table(:<model>) do
add :ancestry, :string

timestamps()
end
create index(:<model>, [:ancestry])
end
end
```

```bash
mix ecto.migrate
```

Add `use Ancestry` to your model ex:

```elixir
defmodule Page do
use Ecto.Schema
use Ancestry

import Ecto.Changeset

schema "pages" do
field :ancestry, :string
end

def changeset(struct, params) do
struct
|> cast(params, [:ancestry])
end
end

```

### TODO

- [ ] roots
- [ ] ancestors
- [ ] children
- [ ] descendants
- [ ] siblings
- [ ] tests

## License

This package is available as open source under the terms of the [MIT License](LICENSE.md).
1 change: 1 addition & 0 deletions lib/ancestry.ex
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@ defmodule Ancestry do
@orphan_stategy options[:orphan_strategy] || :destroy


# ---- Delete a model and apply_orphan_strategy
def delete(model) do
multi =
Multi.new
Expand Down

0 comments on commit da39968

Please sign in to comment.