Popularity
5.5
Declining
Activity
0.0
Stable
31
3
17

Monthly Downloads: 538
Programming language: Elixir
License: Apache License 2.0
Latest version: v0.2.0

ecto_ordered alternatives and similar packages

Based on the "ORM and Datamapping" category

Do you think we are missing an alternative of ecto_ordered or a related project?

Add another 'ORM and Datamapping' Package

README

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, virtual: true
    field, :rank, :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, virtual: true
  end

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