Skip to content

Instantly share code, notes, and snippets.

@karlosmid
Created May 17, 2020 12:37
Show Gist options
  • Save karlosmid/75e27fbb6a55695277cb662df4b967a1 to your computer and use it in GitHub Desktop.
Save karlosmid/75e27fbb6a55695277cb662df4b967a1 to your computer and use it in GitHub Desktop.
defmodule Testivator.CRM.DataFile do
@moduledoc """
DataFile schema
"""
use Testivator.Web, :model
use Arc.Ecto.Schema
alias Testivator.CRM.Charter
alias Testivator.CRM.DataFile
schema "datafiles" do
field(:file, Testivator.File.Type)
belongs_to(:charter, Charter)
timestamps()
end
def changeset(%DataFile{} = datafile, attrs \\ %{}) do
datafile
|> cast(attrs, [:charter_id])
|> cast_attachments(attrs, [:file])
|> validate_required(:file)
|> assoc_constraint(:charter)
end
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment