mirror of
https://github.com/ash-project/ash_postgres.git
synced 2024-09-20 21:43:12 +12:00
38 lines
791 B
Elixir
38 lines
791 B
Elixir
defmodule AshPostgres.Test.Post do
|
|
@moduledoc false
|
|
use Ash.Resource,
|
|
data_layer: AshPostgres.DataLayer
|
|
|
|
postgres do
|
|
table "posts"
|
|
repo AshPostgres.TestRepo
|
|
end
|
|
|
|
actions do
|
|
read(:read)
|
|
create(:create)
|
|
end
|
|
|
|
attributes do
|
|
attribute(:id, :uuid, primary_key?: true, default: &Ecto.UUID.generate/0)
|
|
attribute(:title, :string)
|
|
attribute(:score, :integer)
|
|
attribute(:public, :boolean)
|
|
end
|
|
|
|
relationships do
|
|
has_many(:comments, AshPostgres.Test.Comment, destination_field: :post_id)
|
|
end
|
|
|
|
aggregates do
|
|
count(:count_of_comments, :comments)
|
|
|
|
count :count_of_comments_called_match, :comments do
|
|
filter(title: "match")
|
|
end
|
|
|
|
first :first_comment, :comments, :title do
|
|
sort(title: :asc_nils_last)
|
|
end
|
|
end
|
|
end
|