ecto_ordered v0.2.0-beta1 EctoOrdered

EctoOrdered provides changeset methods for updating ordering an ordering column

It should be added to your schema like so:

defmodule OrderedListItem do
  use Ecto.Schema
  import Ecto.Changeset

  schema "ordered_list_item" do
    field :title,            :string
    field :position,         :integer, virtual: true
    field :rank,             :integer
    field :move,             :any, virtual: true
  end

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

Summary

Functions

Returns a changeset which will include updates to the other ordered rows within the same transaction as the insertion, deletion or update of this row

Functions

do_move(arg1, options, changeset)
set_order(changeset, position_field \\ :position, rank_field \\ :rank, scope_field \\ nil)

Returns a changeset which will include updates to the other ordered rows within the same transaction as the insertion, deletion or update of this row.

The arguments are as follows:

  • changeset the changeset which is part of the ordered list
  • position_field the (virtual) field in which the order is set
  • rank_field the field in which the ranking should be stored
  • scope the field in which the scope for the order should be stored (optional)