WIGGLES
WIGGLES
AEAsh Elixir
Created by WIGGLES on 7/6/2023 in #support
Polymorphic Self References
Can't seem to figure out how to accomplish the following. I have a polymorphic table that is meant to model a tree relationship. this of course requires a belongs_to and has_many relationship to itself. How do I go about defining a self referential relationship that is mean to pickup on context provided by the consumer? Such that all the relationships are within the same table?
relationships do
belongs_to :parent, __MODULE__
has_many :children, __MODULE__, destination_attribute: :parent_id
end

postgres do
polymorphic? true

repo Butsby.Repo

references do
reference :parent, on_delete: :delete
end
end
relationships do
belongs_to :parent, __MODULE__
has_many :children, __MODULE__, destination_attribute: :parent_id
end

postgres do
polymorphic? true

repo Butsby.Repo

references do
reference :parent, on_delete: :delete
end
end
9 replies
AEAsh Elixir
Created by WIGGLES on 6/27/2023 in #support
custom step inside of map step in a flow.
It appears that the DSL is not setup to handle nested custom steps. When trying to use a custom step inside of a parent map step, I get a undefined function custom/3 (there is no such import) error.
17 replies
AEAsh Elixir
Created by WIGGLES on 6/1/2023 in #support
Read Action Prepare does not load aggregate
I have a resource with a count aggregate for a child resource
aggregates do
count :response_count, :responses
end
aggregates do
count :response_count, :responses
end
I then have a default read action that uses prepare and build to load the aggregate
read :read do
primary? true
pagination offset?: true, keyset?: true, required?: false

prepare build(aggregate: {:response_count, :count, :responses}, load: [:responses])
end
read :read do
primary? true
pagination offset?: true, keyset?: true, required?: false

prepare build(aggregate: {:response_count, :count, :responses}, load: [:responses])
end
Note that I have currently loaded responses to use the length method to get a count, but whenever I attempt to access response_count it returns an Ash.NotLoaded<:aggregate> value. Loving ASH btw, It cuts down on a lot of the boilerplate that you get with normal Phoenix contexts.
3 replies
AEAsh Elixir
Created by WIGGLES on 5/31/2023 in #support
Ash Form Questions
Are there any gotchas with AshPhoenix.Form.create_for and child resources inside an inputs_for? I'm getting an unkown error and I'm not sure what's going wrong because the example in the documentation seems to indicate that the child object in a has_many relationship just gets created?
resource |>
Form.for_create(action,
api: api,
forms: forms,
prepare_source: prepare_source
)

resource |>
Form.for_create(action,
api: api,
forms: forms,
prepare_source: prepare_source
)

forms={[
answers: [
type: :list,
resource: PollAnswer,
create_action: :create
]
]}

forms={[
answers: [
type: :list,
resource: PollAnswer,
create_action: :create
]
]}

<fieldset>
<legend>Answers</legend>
<.inputs_for :let={f_answer} field={f[:answers]}>
<.input field={f_answer[:label]} label="Label" />
<.icon
phx-click="remove_form"
phx-value-path={f_answer.name}
phx-target={"##{@id}"}
name="hero-minus"
/>
</.inputs_for>
<menu>
<.icon
phx-click="add_form"
phx-value-path={f[:answers].name}
phx-target={"##{@id}"}
name="hero-plus"
/>
</menu>
</fieldset>
<fieldset>
<legend>Answers</legend>
<.inputs_for :let={f_answer} field={f[:answers]}>
<.input field={f_answer[:label]} label="Label" />
<.icon
phx-click="remove_form"
phx-value-path={f_answer.name}
phx-target={"##{@id}"}
name="hero-minus"
/>
</.inputs_for>
<menu>
<.icon
phx-click="add_form"
phx-value-path={f[:answers].name}
phx-target={"##{@id}"}
name="hero-plus"
/>
</menu>
</fieldset>
My guess is that there's something I need to opt into configuration wise in the resource to ahve this work?
57 replies