Current section

Files

Jump to
ami lib ami country.ex
Raw

lib/ami/country.ex

defmodule Ami.Country do
use Ecto.Schema
import Ecto.Query
alias Ami.{
Repo,
City,
Profile
}
schema "countries" do
field(:iso, :string)
field(:name, :string)
has_many(:cities, City)
has_many(:profiles, Profile)
end
def search_by_name(query) do
from(c in __MODULE__, where: ilike(c.name, ^"%#{query}%"))
|> Repo.all()
end
def for_select_field() do
from(
c in __MODULE__,
order_by: [asc: c.name],
select: [:id, :name]
)
|> Repo.all()
end
end