bryan
bryan
AEAsh Elixir
Created by bryan on 7/7/2023 in #support
Possible to use relationships for Identity?
defmodule One.Exam.QuestionParagraph do
use Ash.Resource,
data_layer: AshPostgres.DataLayer

postgres do
table "question_paragraphs"
repo One.Repo
end

actions do
defaults [:create, :read, :update, :destroy]
end

attributes do
uuid_primary_key :id
attribute :ordinal, :integer
attribute :text, :string
attribute :image, :string
end

relationships do
belongs_to :question, One.Exam.Question
end

identities do
identity :order, [:ordinal, :question]
end
end
defmodule One.Exam.QuestionParagraph do
use Ash.Resource,
data_layer: AshPostgres.DataLayer

postgres do
table "question_paragraphs"
repo One.Repo
end

actions do
defaults [:create, :read, :update, :destroy]
end

attributes do
uuid_primary_key :id
attribute :ordinal, :integer
attribute :text, :string
attribute :image, :string
end

relationships do
belongs_to :question, One.Exam.Question
end

identities do
identity :order, [:ordinal, :question]
end
end
I want paragraphs belonging to a question to be ordered so they have an ordinal which needs to be unique, but only for that specific Question. How do I do that?
4 replies