Ash Elixir

AE

Ash Elixir

Join the community to ask questions about Ash Elixir and get answers from other members.

Join

support

showcase

today-i-learned

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} =...

manage_relationship argument not relating primary key to resource

resource ``` create :add_to_group do argument :group, :uuid do allow_nil? false...

Calculations Using Relationships

I'm writing a simple chat app to try to learn Ash. I have models like below and I'd like to write an :unread_count calculation on the Channel. It would take the current user as the actor and find the associated member of the channel, use that :last_read_at time to filter down the messages associated with the channel to ones that has a :created_at after that time, and count them. I'm having a hard time figuring out how to do that based on the examples. What I think I want is something like:...

Ash Admin dependency for newest liveview

Because your app depends on ash_admin ~> 0.8.1 which depends on phoenix_live_view ~> 0.18.3, phoenix_live_view ~> 0.18.3 is required.
So, because your app depends on phoenix_live_view ~> 0.19.0, version solving failed.
Because your app depends on ash_admin ~> 0.8.1 which depends on phoenix_live_view ~> 0.18.3, phoenix_live_view ~> 0.18.3 is required.
So, because your app depends on phoenix_live_view ~> 0.19.0, version solving failed.
Anyway to solve this? or have to wait for update? create an issue?...

Ambiguous Call during Compile because of Extension

I'm creating an extension and I tried adding an actions option to it, but it won't compile the resources anymore because it cant tell which actions function to use. ``` == Compilation error in file test/support/policy.ex == ** (CompileError) test/support/policy.ex:52: function actions/1 imported from both Demo.Extensions.Rbac.Rbac.Role.Options and Ash.Resource.Dsl, call is ambiguous...

How not to select fields when loading a resource

Is there a way in Ash to not select a field when loading a resource? We have some fields in the DB that are really large and we don't need to select them most of the time. Is there a way to tell Ash not to select that field for this particular load or action?...

How to put the same value at multiple places in a fragment?

Say I have a custom postgres function and Is it possible to do the following fragment fragment("SELECT my_custom_function(1/<rate>, 2/<rate>, 3*<rate>) FROM lookup_values WHERE id=<id>", rate, id)? Today, I will need to do fragment("SELECT my_custom_function(1/?, 2/?, 3*?) FROM lookup_values WHERE id=?", rate, rate, rate, id)...

How do you sort by substring?

Current in my resource ```actions do defaults [:read] read :list do...