What is the equivalent of Ecto's Repo.exists? in Ash?
Let's say I have a
Post
resource, and I want to create a read
action that instead of returning a specific Post
, I want it just to check if the post exists and return only true/false just like Ecto's Repo.exists?
does.
Is that possible with Ash?5 Replies
Currently we do not have that, but it will be added at some point. You can write a generic action in the meantime to simulate it
Or you could use
Ash.Query.datalayer_query
and pass that to ecto.Here is my solution:
Are you aware of some way to to the same without having to use
data_layer_query
? I tried simulating the exists?
feature with Ash.Query.select(1) |> Ash.Query.limit(1)
but using 1
for the select function call is not supported.doing
select(:id)
would be roughly equivalent
but currently its either selecting a field or using the repo like you did@Zach Daniel does this solution respect multitenancy and policies? Not sure if those are apply at the query or action level
It does not. Those happen at the action level. Actually I’d have to double check on multitenancy
But that’s the reason I’d suggest opting for the
select id
approach.