Failz
Failz
AEAsh Elixir
Created by Failz on 5/25/2025 in #support
ash_double_entry and updating transfers
I see a unit test that is capable of updating a transfer. However I cannot get it to work and see this error.
* ** (CaseClauseError) no case clause matching: {:error, "Cannot destroy a transfer atomically if balances must be destroyed manually, or if balance is being updated"}
* ** (CaseClauseError) no case clause matching: {:error, "Cannot destroy a transfer atomically if balances must be destroyed manually, or if balance is being updated"}
I am using Postgres (16.1) and saw this in the docs:
transfer do
# configure the other resources it will interact with
account_resource YourApp.Ledger.Account
balance_resource YourApp.Ledger.Balance

# you only need this if you are using `postgres`
# and so cannot add the `references` block shown below

# destroy_balances? true
end
transfer do
# configure the other resources it will interact with
account_resource YourApp.Ledger.Account
balance_resource YourApp.Ledger.Balance

# you only need this if you are using `postgres`
# and so cannot add the `references` block shown below

# destroy_balances? true
end
cascading destroys

If you are not using a data layer capable of automatic cascade deletion, you must add destroy_balances? true to the transfer resource! We do this with the references block in ash_postgres as shown above.
cascading destroys

If you are not using a data layer capable of automatic cascade deletion, you must add destroy_balances? true to the transfer resource! We do this with the references block in ash_postgres as shown above.
I've played with both of these settings but still come up against the error I posted above. The mention of these two settings is confusing. Postgres is capable of "automatic cascade deletion", no? What am I missing? Note: There's no ash_double_entry tag.
40 replies
AEAsh Elixir
Created by Failz on 5/21/2025 in #support
enabling multi tenant for graphql
turning on graphql for first time in my app (multi tenant)
# router.ex
import AshAuthentication.Plug.Helpers

pipeline :graphql do
plug :load_from_bearer
plug AshGraphql.Plug
end
# router.ex
import AshAuthentication.Plug.Helpers

pipeline :graphql do
plug :load_from_bearer
plug AshGraphql.Plug
end
and my first query blows up with: Queries against the App.Elevate.Group resource require a tenant to be specified which makes sense. So reading ash graphl docs:
AshGraphql.Plug

Automatically set up the GraphQL actor and tenant.

Adding this plug to your pipeline will automatically set the actor and tenant if they were previously put there by Ash.PlugHelpers.set_actor/2 or Ash.PlugHelpers.set_tenant/2.
AshGraphql.Plug

Automatically set up the GraphQL actor and tenant.

Adding this plug to your pipeline will automatically set the actor and tenant if they were previously put there by Ash.PlugHelpers.set_actor/2 or Ash.PlugHelpers.set_tenant/2.
Adding import Ash.PlugHelpers to bring in set_tenant and the IDE complains that set_actor is ambiguous. Does it matter which set_actor is used?
19 replies
AEAsh Elixir
Created by Failz on 5/19/2025 in #today-i-learned
pgsql autocomplete and syntax highlighting
enjoy postgres nerds!! https://github.com/dbcli/pgcli
1 replies
AEAsh Elixir
Created by Failz on 5/16/2025 in #support
receiving an Ash Error and don't understand why
question about this error. I'm trying to setup something similar in my app that the Tunez book does. Following an artist, but I'm wanting to like a post. Here's the code
# post.ex (resource)
has_many :like_relationships, App.Elevate.PostLike

many_to_many :likes, App.Accounts.User do
join_relationship :like_relationships
destination_attribute_on_join_resource :user_id
end

# post_like.ex (resource)
belongs_to :post, App.Elevate.Post do
allow_nil? false
primary_key? true
end

belongs_to :user, App.Accounts.User do
allow_nil? false
primary_key? true
end

# user.ex (resource)

has_many :like_relationships, App.Elevate.PostLike do
destination_attribute :user_id
end

many_to_many :liked_posts, App.Elevate.Post do
join_relationship :like_relationships
source_attribute_on_join_resource :user_id
end
# post.ex (resource)
has_many :like_relationships, App.Elevate.PostLike

many_to_many :likes, App.Accounts.User do
join_relationship :like_relationships
destination_attribute_on_join_resource :user_id
end

# post_like.ex (resource)
belongs_to :post, App.Elevate.Post do
allow_nil? false
primary_key? true
end

belongs_to :user, App.Accounts.User do
allow_nil? false
primary_key? true
end

# user.ex (resource)

has_many :like_relationships, App.Elevate.PostLike do
destination_attribute :user_id
end

many_to_many :liked_posts, App.Elevate.Post do
join_relationship :like_relationships
source_attribute_on_join_resource :user_id
end
The attached message shows the queries to start to fire off but then runs into an Ash exception.
7 replies