2022-12-18 01:57:25 +13:00
|
|
|
defmodule AshPostgres.Test.User 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 20:23:39 +13:00
|
|
|
defaults([:create, :read, :update, :destroy])
|
2024-02-29 15:23:15 +13:00
|
|
|
|
|
|
|
read :active do
|
|
|
|
filter(expr(active))
|
2024-05-17 10:28:43 +12:00
|
|
|
|
|
|
|
pagination do
|
|
|
|
offset?(true)
|
|
|
|
keyset?(true)
|
|
|
|
countable(true)
|
|
|
|
required?(false)
|
|
|
|
end
|
|
|
|
end
|
|
|
|
|
|
|
|
read :keyset do
|
|
|
|
pagination do
|
|
|
|
keyset?(true)
|
|
|
|
countable(true)
|
|
|
|
required?(false)
|
|
|
|
end
|
2024-02-29 15:23:15 +13:00
|
|
|
end
|
|
|
|
end
|
|
|
|
|
|
|
|
calculations do
|
|
|
|
calculate(:active, :boolean, expr(is_active == true))
|
2022-12-18 01:57:25 +13:00
|
|
|
end
|
|
|
|
|
|
|
|
attributes do
|
2022-12-18 20:23:39 +13:00
|
|
|
uuid_primary_key(:id)
|
2024-03-28 09:52:28 +13:00
|
|
|
attribute(:is_active, :boolean, public?: true)
|
|
|
|
attribute(:name, :string, public?: true)
|
2022-12-18 01:57:25 +13:00
|
|
|
end
|
2022-12-18 20:23:39 +13:00
|
|
|
|
2022-12-18 01:57:25 +13:00
|
|
|
postgres do
|
|
|
|
table "users"
|
|
|
|
repo(AshPostgres.TestRepo)
|
|
|
|
end
|
|
|
|
|
|
|
|
relationships do
|
2024-02-15 05:04:06 +13:00
|
|
|
belongs_to :organization, AshPostgres.Test.Organization do
|
2024-03-28 09:52:28 +13:00
|
|
|
public?(true)
|
2024-02-15 05:04:06 +13:00
|
|
|
attribute_writable?(true)
|
|
|
|
end
|
|
|
|
|
2024-03-28 09:52:28 +13:00
|
|
|
has_many(:accounts, AshPostgres.Test.Account) do
|
|
|
|
public?(true)
|
|
|
|
end
|
2022-12-18 01:57:25 +13:00
|
|
|
end
|
2022-12-18 20:23:39 +13:00
|
|
|
end
|