2022-12-18 01:57:25 +13:00
|
|
|
defmodule AshPostgres.Test.User do
|
|
|
|
@moduledoc false
|
|
|
|
use Ash.Resource, data_layer: AshPostgres.DataLayer
|
|
|
|
|
|
|
|
actions do
|
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))
|
|
|
|
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)
|
|
|
|
attribute(:is_active, :boolean)
|
2023-11-16 14:56:09 +13:00
|
|
|
attribute(:name, :string)
|
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
|
|
|
|
attribute_writable?(true)
|
|
|
|
end
|
|
|
|
|
2022-12-18 20:23:39 +13:00
|
|
|
has_many(:accounts, AshPostgres.Test.Account)
|
2022-12-18 01:57:25 +13:00
|
|
|
end
|
2022-12-18 20:23:39 +13:00
|
|
|
end
|