Bypassing Multitenancy on Destroy Actions

My goal is to delete any invitation that is expired using a cron job (Oban)
destroy :delete_expired_invitation do
multitenancy :bypass
filter expr(expires_at <= now())
end
destroy :delete_expired_invitation do
multitenancy :bypass
filter expr(expires_at <= now())
end
But multitenancy doesn't seem to be a valid option for the destroy action DSL, and I'm not sure about the filter line there either 🤔 what can I do in this case?
Solution:
This is working though ```elixir MyApp.Establishments.Invitation |> Ash.Query.for_read(:expired)...
Jump to solution
4 Replies
ZachDaniel
ZachDaniel•2mo ago
Hm...are you on the latest ash version? The bypass option was added recently
Joan Gavelán
Joan GavelánOP•2mo ago
Just upgraded, but still, it seems like is not a valid option
Joan Gavelán
Joan GavelánOP•2mo ago
No description
Solution
Joan Gavelán
Joan Gavelán•2mo ago
This is working though
MyApp.Establishments.Invitation
|> Ash.Query.for_read(:expired)
|> Ash.bulk_destroy!(:destroy, %{}, authorize?: false, tenant: :bypass)
MyApp.Establishments.Invitation
|> Ash.Query.for_read(:expired)
|> Ash.bulk_destroy!(:destroy, %{}, authorize?: false, tenant: :bypass)

Did you find this page helpful?