defmodule Moneybadger.Ledger.Expense do
use Ash.Resource,
data_layer: AshPostgres.DataLayer
alias Moneybadger.Ledger.Currency
attributes do
uuid_primary_key :id
attribute :name, :string do
allow_nil? false
end
attribute :amount, :decimal do
allow_nil? false
end
attribute :date, :date
timestamps()
end
relationships do
belongs_to :currency, Currency do
allow_nil? false
attribute_type :string
destination_attribute :code
end
end
actions do
defaults [:create, :read]
end
code_interface do
...
end
postgres do
table "expenses"
repo Moneybadger.Repo
references do
reference :currency, on_delete: :delete, on_update: :update
end
end
end
defmodule Moneybadger.Ledger.Expense do
use Ash.Resource,
data_layer: AshPostgres.DataLayer
alias Moneybadger.Ledger.Currency
attributes do
uuid_primary_key :id
attribute :name, :string do
allow_nil? false
end
attribute :amount, :decimal do
allow_nil? false
end
attribute :date, :date
timestamps()
end
relationships do
belongs_to :currency, Currency do
allow_nil? false
attribute_type :string
destination_attribute :code
end
end
actions do
defaults [:create, :read]
end
code_interface do
...
end
postgres do
table "expenses"
repo Moneybadger.Repo
references do
reference :currency, on_delete: :delete, on_update: :update
end
end
end