mirror of
https://github.com/ash-project/ash_postgres.git
synced 2024-09-20 21:43:12 +12:00
37cc01957d
* WIP * chore: fix mix.lock merge issues * improvement: upgrade to 3.0 * chore: remove `repo.to_tenant` * chore: continue removal of unnecessary helper * chore: use `Ash.ToTenant`
58 lines
1.3 KiB
Elixir
58 lines
1.3 KiB
Elixir
defmodule AshPostgres.Test.ComplexCalculations.Skill do
|
|
@moduledoc false
|
|
use Ash.Resource,
|
|
domain: AshPostgres.Test.ComplexCalculations.Domain,
|
|
data_layer: AshPostgres.DataLayer
|
|
|
|
actions do
|
|
default_accept(:*)
|
|
|
|
defaults([:create, :read, :update, :destroy])
|
|
end
|
|
|
|
aggregates do
|
|
first :latest_documentation_status, [:documentations], :status do
|
|
sort(timestamp: :desc)
|
|
end
|
|
end
|
|
|
|
attributes do
|
|
uuid_primary_key(:id)
|
|
attribute(:removed, :boolean, default: false, allow_nil?: false, public?: true)
|
|
end
|
|
|
|
calculations do
|
|
calculate :status, :atom do
|
|
calculation(
|
|
expr(
|
|
if is_nil(latest_documentation_status) do
|
|
:pending
|
|
else
|
|
latest_documentation_status
|
|
end
|
|
)
|
|
)
|
|
end
|
|
end
|
|
|
|
postgres do
|
|
table "complex_calculations_skills"
|
|
repo(AshPostgres.TestRepo)
|
|
end
|
|
|
|
relationships do
|
|
belongs_to(:certification, AshPostgres.Test.ComplexCalculations.Certification) do
|
|
public?(true)
|
|
end
|
|
|
|
has_many :documentations, AshPostgres.Test.ComplexCalculations.Documentation do
|
|
public?(true)
|
|
sort(timestamp: :desc, inserted_at: :desc)
|
|
end
|
|
|
|
has_one :latest_documentation, AshPostgres.Test.ComplexCalculations.Documentation do
|
|
public?(true)
|
|
sort(timestamp: :desc, inserted_at: :desc)
|
|
end
|
|
end
|
|
end
|