defmodule DaProductApp.Merchants.Merchant do @moduledoc """ Merchant entity normalized from RespValQr merchant block. """ use Ecto.Schema import Ecto.Changeset alias DaProductApp.Merchants.MerchantInvoice schema "merchants" do field :mid, :string field :sid, :string field :tid, :string field :sub_code, :string field :merchant_type, :string field :merchant_genre, :string field :onboarding_type, :string field :inst_code, :string field :brand_name, :string field :legal_name, :string field :franchise_name, :string field :ownership_type, :string field :country_code, :string field :network_inst_id, :string has_many :invoices, MerchantInvoice timestamps() end @required ~w(mid tid)a @optional ~w(sid sub_code merchant_type merchant_genre onboarding_type inst_code brand_name legal_name franchise_name ownership_type country_code network_inst_id)a def changeset(struct, attrs) do struct |> cast(attrs, @required ++ @optional) |> validate_required(@required) |> unique_constraint([:mid, :tid]) end end