Skip to content
Ecto extension for ordered models
Elixir
Fetching latest commit…
Cannot retrieve the latest commit at this time.
Failed to load latest commit information.
config
lib
test
.gitignore Initial source code import Jan 13, 2015
.travis.yml
README.md
mix.exs
mix.lock

README.md

EctoOrdered

Ecto extension to support ordered list items. Similar to acts_as_list, but for Ecto

Examples

# Global positioning
defmodule MyModel do
  use Ecto.Schema
  import EctoOrdered

  schema "models" do
    field :position, :integer
  end

  def changeset(model, params) do
    model
    |> cast(params, [], [:position])
    |> set_order(:position)
  end
end

# Scoped positioning
defmodule MyModel do
  use Ecto.Model
  use EctoOrdered, scope: :reference_id

  schema "models" do
    field :reference_id, :integer
    field :position,     :integer
  end

  def changeset(model, params) do
    model
    |> cast(params, [], [:position, :reference_id])
    |> set_order(:position, :reference_id)
  end
end
Something went wrong with that request. Please try again.