Ash Framework

AF

Ash Framework

The Elixir backend framework for unparalleled productivity. Declarative tools that let you stop wasting time. Use with Phoenix LiveView or build APIs in minutes for your front-end of choice.

Join

support

showcase

today-i-learned

Differences between UUID primary keys in Ecto vs Ash

As far as I can tell, the Ash Resource special attribute uuid_primary_key unwraps into: ```elixir attribute :id, :uuid do writeable? false default &Ash.UUID.generate/0...

Starting a Phoenix/Ash project with minimal cruft

Howdy there. I've been trying the tutorials from the Ash website (both "Get Started" and "Get Started with Ash and Phoenix"). As I was going through, I couldn't help but wonder, "is there a way to do this without Phoenix's Ecto?" In other words, if I'm planning on using Ash for all the domain logic, and Ash is going to use Ecto, can I initialize Pheonix without ecto and still get Ash to work right (since I'll be using Ecto with it)? Context:...

Check a policy manually

Is there a way in Ash to check a policy manually? I want to check if a particular actor has the ability to update a specific resource. I wasn't able to find how to do that. My use case is I'm creating a resource by passing in a Google Cloud storage signed url and I need to check if the path in the signed url is valid. Right now I have this:...

How to insert a record with its nested children?

First, I'd love to thank everyone and especially Zash for the awesome work done in Ash I have a few resources with some relationships between them, for brevity I'll only copy the relevant parts ```elixir...

Ash dropping FilterCheck if there's `authorize_if always()`

Hi, I've got a resource that in it's action has:
authorize_if MyApp.FilterByActorId
authorize_if always()
authorize_if MyApp.FilterByActorId
authorize_if always()
...

How do relationships with composite keys work?

I found this mention of composite keys in the docs: ```elixir has_many :composite_key_posts, MyApp.CompositeKeyPost do destination_attribute :author_id end...

Policy checks on related resources

I have been looking for quite some time so this may be a noob ish question. I have a couple answers potentially but I'd like to know kind of the standard way to write a policy for a resource where the relationship to that resource is how I would authorize the actor. For example Let's say I have a GroupRequest resource which represents a users request to join a group (contains a group_id and user_id) I also have a Group that has a group_admin relationship which belongs to a user....

Using manage_relationship to delete a related record

I have an action that accepts the ID of a related record. It should delete that record. However, when I tried using the type: :remove option, Ash responds with Invalid value provided for notes: changes would create a new related record. Is this the right approach? Or should I manually delete the record?

Confused about `one_of` vs `attribute_equals`

Still messing around and encountered a confusing behavior with validations. I have a :verify action on a resource, which I only want to run on resources which have :role set to :unverified The below works as expected (produces valid/invalid changesets as expected): ``` update :verify do #custom action to verify an unverified user validate attribute_equals(:role, :unverified) #only verify unverified users change set_attribute(:role, :verified)...

Calculatated fields and AshGraphQL

How can I query calculated fields in when graphql . the fields are virtual they don't exist as attributes. ?

Bypass not applying - had to pass actor again in load

Hi! I fought with this for an embarrassingly long time so I'm just gonna stick it here for SEO posterity. I thought my superuser/staff bypass was inexplicably failing – it's at the top, what's the deal??? – but it turns out the policy system just wasn't seeing my actor at all where I assumed it was. I had to pass the actor in again on the load! call. not sure if there's a better way to do this type of thing but this is what's working now:...

AshJsonApi + Managed Relationships

Are there any examples of AshJsonApi, the docs seem outdated. Im trying to get managed relationships to work through a 'parent' resource.

Can You Add Additional Attributes to ash_authentication_phoenix?

I went through the tutorial for and have password/email auth working. I'd like to add a role attribute to my user resource so I did the below: ``` attributes do uuid_primary_key :id attribute :email, :ci_string, allow_nil?: false...

How to determine if the current page is the last or first page in Keyset pagination

I may be missing this from the documentation, but is there a way to find out if the current "page" is the firsrt or the last?

Full debug SQL

Hi, during development, the sql statement is printed out by the AshPostgres.DataLayer.run_aggregate_query/3, at: lib/data_layer.ex:738 A long enough sql would be truncated. How do I get the full sql without truncation? Thanks!...

Setting defaults for a form input that is an argument and not an attribute?

I have an update action that takes an argument. In the form for this action, I need to set the default value for the form input. The default value is dependent on the current state of the resource being updated. I explored using the default option for an action argument; however, It accepts a zero-argument function, so there's no way to get the resource being updated. I explored using the prepare_params option for AshPhoenix.Form.for_update but I couldn't find any examples. It's arrity 2 and receives the params but is only called when the form is validated or submitted....

How to make fields optional for graphql api?

Kind of analogous to the way hide_fields is used, is there a way I can allow a field to be nil for the Graphql API when it is not allowed to be nil as an attribute?

Understanding value_is_key option when managing relationships

Given a relation that uses a ci_string (not uuid): ``` belongs_to :feature, Environments.Feature do allow_nil? false source_attribute :feature_key...

many_to_many exception after updating Ash

Previous version was 2.6.31. I updated to 2.11.8 today and an existing many_to_many association that I had is now raising an exception. Did something change? Here are my resources: ```elixir...

How to programatically add a policy to a resource?

I might be missing something here related to Spark, but how do I programatically add a policy? (e.g. using a Spark extension) ```elixir def transform(dsl_state) do {:ok, policy} =...