mirror of
https://github.com/ash-project/ash_postgres.git
synced 2024-09-20 21:43:12 +12:00
36 lines
631 B
Elixir
36 lines
631 B
Elixir
|
defmodule AshPostgres.Test.Account do
|
||
|
@moduledoc false
|
||
|
use Ash.Resource, data_layer: AshPostgres.DataLayer
|
||
|
|
||
|
actions do
|
||
|
defaults([:create, :read, :update, :destroy])
|
||
|
end
|
||
|
|
||
|
aggregates do
|
||
|
first(:user_is_active, :user, :is_active)
|
||
|
end
|
||
|
|
||
|
attributes do
|
||
|
uuid_primary_key(:id)
|
||
|
attribute(:is_active, :boolean)
|
||
|
end
|
||
|
|
||
|
calculations do
|
||
|
calculate(
|
||
|
:active,
|
||
|
:boolean,
|
||
|
expr(is_active && user_is_active),
|
||
|
load: [:user_is_active]
|
||
|
)
|
||
|
end
|
||
|
|
||
|
postgres do
|
||
|
table "accounts"
|
||
|
repo(AshPostgres.TestRepo)
|
||
|
end
|
||
|
|
||
|
relationships do
|
||
|
belongs_to(:user, AshPostgres.Test.User)
|
||
|
end
|
||
|
end
|