Last active
July 24, 2020 04:23
-
-
Save zachdaniel/b80256a7b4603813f0116389dad21bea to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
defmodule AshExample.Ticket do | |
use Ash.Resource, | |
data_layer: AshPostgres.DataLayer, | |
authorizers: [ | |
AshPolicyAuthorizer.Authorizer | |
], | |
extensions: [ | |
AshJsonApi.Resource | |
] | |
policies do | |
access_type :filter | |
policy do | |
name "Here is a name!" | |
authorize_if relates_to_actor_via(:reporter) | |
authorize_if relates_to_actor_via(:representative) | |
end | |
end | |
postgres do | |
table "tickets" | |
repo AshExample.Repo | |
end | |
json_api do | |
type "ticket" | |
fields [:subject] | |
routes do | |
base "/tickets" | |
get :default | |
index :default | |
relationship :linked_tickets, :default | |
post_to_relationship :linked_tickets, :default | |
patch_relationship :linked_tickets, :default | |
end | |
end | |
actions do | |
read :default | |
create :default | |
update :default | |
end | |
attributes do | |
attribute :id, :uuid do | |
primary_key?(true) | |
default(&Ecto.UUID.generate/0) | |
end | |
attribute :subject, :string | |
end | |
relationships do | |
belongs_to :reporter, AshExample.User | |
belongs_to :representative, AshExample.Representative | |
many_to_many :linked_tickets, AshExample.Ticket, | |
through: AshExample.TicketLink, | |
source_field: :id, | |
destination_field: :id, | |
source_field_on_join_table: :source_ticket_id, | |
destination_field_on_join_table: :destination_ticket_id, | |
join_attributes: [:link_type] | |
end | |
end |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment