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
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 listposition_field
the (virtual) field in which the order is setrank_field
the field in which the ranking should be storedscope
the field in which the scope for the order should be stored (optional)