morfertaw
morfertaw
Explore posts from servers
AEAsh Elixir
Created by morfertaw on 9/25/2023 in #support
Attributes on `many_to_many` join/through resources.
Yeah, this is exactly what I was hoping for. Cheers!
4 replies
AEAsh Elixir
Created by morfertaw on 9/23/2023 in #support
Identity on `attribute :some_attribute, {:array , EmbeddedResource}`
I'm not sure how I would do so with a resource and relationship. Regardless thanks for the response.
8 replies
AEAsh Elixir
Created by morfertaw on 9/21/2023 in #support
Understanding "manage_relationship"
It works as expected now! I had incorrectly assumed that, by default, it would use all identities and if any matched, trigger the on_match.
6 replies
AEAsh Elixir
Created by morfertaw on 9/21/2023 in #support
Understanding "manage_relationship"
ReactantSource
defmodule Flame.App.Resources.ReactantSource do
...
actions do
defaults [:create, :read, :update, :destroy]
end

relationships do
belongs_to :reactant, Flame.App.Resources.Reactant, primary_key?: true, allow_nil?: false
belongs_to :source, Flame.App.Resources.Source, primary_key?: true, allow_nil?: false
end
...
end
defmodule Flame.App.Resources.ReactantSource do
...
actions do
defaults [:create, :read, :update, :destroy]
end

relationships do
belongs_to :reactant, Flame.App.Resources.Reactant, primary_key?: true, allow_nil?: false
belongs_to :source, Flame.App.Resources.Source, primary_key?: true, allow_nil?: false
end
...
end
If I create a new Reactant as follows.
{:ok, reactant} = Flame.App.Resources.Reactant
|> Ash.Changeset.new(%{identity: "test_reactant"})
|> Ash.Changeset.for_create(:define, %{
source_definitions: [%{description: "earth"}, %{description: "space"}]
})
|> Flame.App.create()
{:ok, reactant} = Flame.App.Resources.Reactant
|> Ash.Changeset.new(%{identity: "test_reactant"})
|> Ash.Changeset.for_create(:define, %{
source_definitions: [%{description: "earth"}, %{description: "space"}]
})
|> Flame.App.create()
It works and creates a Reactant while creating and relating two Sources. If I then update the reactant as follows.
reactant =
reactant
|> Ash.Changeset.for_update(:redefine, %{source_definitions: nil})
|> Flame.App.update()
reactant =
reactant
|> Ash.Changeset.for_update(:redefine, %{source_definitions: nil})
|> Flame.App.update()
This also works unrelating both Sources without destroying the Sources from their table. Then if I update the reactant as below.
reactant =
reactant
|> Ash.Changeset.for_update(:redefine, %{source_definitions: [%{description: "earth"}] })
|> Flame.App.update()
reactant =
reactant
|> Ash.Changeset.for_update(:redefine, %{source_definitions: [%{description: "earth"}] })
|> Flame.App.update()
This works as expected relating the existing Source from its table without creating a new Source. But the following two updates fail after this update.
reactant =
reactant
|> Ash.Changeset.for_update(:redefine, %{source_definitions: [%{description: "earth"}, %{description: "mars"}] })
|> Flame.App.update()
# OR
reactant =
reactant
|> Ash.Changeset.for_update(:redefine, %{source_definitions: [%{description: "earth"}, %{description: "space"}] })
|> Flame.App.update()
reactant =
reactant
|> Ash.Changeset.for_update(:redefine, %{source_definitions: [%{description: "earth"}, %{description: "mars"}] })
|> Flame.App.update()
# OR
reactant =
reactant
|> Ash.Changeset.for_update(:redefine, %{source_definitions: [%{description: "earth"}, %{description: "space"}] })
|> Flame.App.update()
The error suggests its trying to create an entry in the join resource ReactantSource which already exists.
6 replies
AEAsh Elixir
Created by morfertaw on 9/18/2023 in #support
AshAuthenticationPhoenix controlling generated routes
Yeah, that seems like the way to go. Thanks!
8 replies
AEAsh Elixir
Created by morfertaw on 9/18/2023 in #support
AshAuthenticationPhoenix controlling generated routes
I want to have admins that are either a role on users or a separate resource. Admins will have access to specific routes when logged in that allow them to register new users and/or admins.
8 replies