Current section

Files

Jump to
ami lib ami education.ex
Raw

lib/ami/education.ex

defmodule Ami.Education do
use Ecto.Schema
use Arc.Ecto.Schema
use Timex
import Ecto.{
Query,
Changeset
}
alias Ami.{
Repo,
Profile
}
schema "educations" do
@timestamps_opts [type: :naive_datetime_usec]
field(:level, :string)
field(:institution, :string)
field(:subject, :string)
field(:date_start, :date)
field(:date_end, :date)
field(:created_at, :utc_datetime_usec)
field(:updated_at, :utc_datetime_usec)
field(:current, :boolean)
field(:education_logo, Ami.EducationLogoUploader.Type)
belongs_to(:profile, Profile)
end
def changeset(education_struct, attrs \\ %{}) do
education_struct
|> cast(attrs, [:level, :institution, :subject, :date_start, :date_end, :created_at, :updated_at, :current, :profile_id])
|> validate_required([:level, :institution, :subject])
|> cast_attachments(attrs, [:education_logo])
|> case do
%{valid?: false, changes: changes} = changeset when changes == %{} ->
%{changeset | action: :ignore}
changeset ->
changeset
end
end
end