Ecosyste.ms: Awesome
An open API service indexing awesome lists of open source software.
https://github.com/zovafit/ecto-ordered
Ecto extension for ordered models
https://github.com/zovafit/ecto-ordered
Last synced: 7 days ago
JSON representation
Ecto extension for ordered models
- Host: GitHub
- URL: https://github.com/zovafit/ecto-ordered
- Owner: zovafit
- Created: 2015-01-13T10:55:37.000Z (almost 10 years ago)
- Default Branch: master
- Last Pushed: 2017-10-12T18:07:02.000Z (about 7 years ago)
- Last Synced: 2024-10-29T08:41:30.862Z (10 days ago)
- Language: Elixir
- Size: 47.9 KB
- Stars: 40
- Watchers: 4
- Forks: 18
- Open Issues: 12
-
Metadata Files:
- Readme: README.md
Awesome Lists containing this project
- freaking_awesome_elixir - Elixir - Ecto extension for ordered models. (ORM and Datamapping)
- fucking-awesome-elixir - ecto_ordered - Ecto extension for ordered models. (ORM and Datamapping)
- awesome-elixir - ecto_ordered - Ecto extension for ordered models. (ORM and Datamapping)
README
EctoOrdered
===========Ecto extension to support ordered list items. Similar to [acts_as_list](https://github.com/swanandp/acts_as_list), but
for [Ecto](https://github.com/elixir-lang/ecto)Examples
--------```elixir
# Global positioning
defmodule MyModel do
use Ecto.Schema
import EctoOrderedschema "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_idschema "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