2022-12-18 01:57:25 +13:00
|
|
|
defmodule AshPostgres.Test.Account do
|
|
|
|
@moduledoc false
|
2024-03-28 09:52:28 +13:00
|
|
|
use Ash.Resource,
|
|
|
|
domain: AshPostgres.Test.Domain,
|
|
|
|
data_layer: AshPostgres.DataLayer
|
2022-12-18 01:57:25 +13:00
|
|
|
|
|
|
|
actions do
|
2024-03-28 09:52:28 +13:00
|
|
|
default_accept(:*)
|
|
|
|
|
2022-12-18 01:57:25 +13:00
|
|
|
defaults([:create, :read, :update, :destroy])
|
|
|
|
end
|
|
|
|
|
|
|
|
aggregates do
|
|
|
|
first(:user_is_active, :user, :is_active)
|
|
|
|
end
|
|
|
|
|
|
|
|
attributes do
|
|
|
|
uuid_primary_key(:id)
|
2024-03-28 09:52:28 +13:00
|
|
|
attribute(:is_active, :boolean, public?: true)
|
2022-12-18 01:57:25 +13:00
|
|
|
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
|
2024-03-28 09:52:28 +13:00
|
|
|
belongs_to(:user, AshPostgres.Test.User) do
|
|
|
|
public?(true)
|
|
|
|
end
|
2022-12-18 01:57:25 +13:00
|
|
|
end
|
|
|
|
end
|