firesidewing

firesidewing

I’m warry of getting involved with Ash due to the abstraction it represents, but i wanted to give it a chance since it seems cool and interesting.

I have a couple of small side projects i manage and wanted to try to duplicate one of the simple ones (basically just CRUD with real time updates, a search function, and some user roles stuff). I’m getting stuck on the basics of managing relationships, I’m not sure how much “magic” to expect or what i need to be doing myself but i can’t seem to get the right incantation to get everything working. Granted, I haven’t been able to put much time into this, but I’ve been running through the docs and feel like i’m stuck in a loop.

I have two resources Contacts and Partners. Partners has a one to many with Contacts.

defmodule AshRevenueGenerator.Partners.Contact do
...
actions do
    defaults [:read, :destroy, update: :*]

    create :create do
      primary? true
      accept [:created_by_user_id]

      change relate_actor(:created_by_user)
    end
  end

...

relationships do
    belongs_to :partner, AshRevenueGenerator.Partners.Partner do
      allow_nil? false
      attribute_writable? true
      public? true
    end

    belongs_to :created_by_user, AshRevenueGenerator.Accounts.User do
      allow_nil? false
      attribute_writable? true
    end
  end
...
end

And for the form, I’m just using the one from the generator, with an added select input for the Partner. The public? true on the attributes and the relationship got me for a while, kind of annoying, would be nice if there was a short hand for it (might be, i haven’t be able to find it though). I’ve tried set_attribute in the action and adding the partner_id to the accepts, i’ve tried manage_relationship(:partner, :partner_id) but didn’t stick with that long. I can’t seem to get all the attributes to save for a contact and then to also be able to set the partner from the form at the same time. Current error the form is giving me is that partner is required (which is true but i’m passing in params with a partner_id set)

Long winded, but is there some sort of guide, or tutorial, or documentation I’m missing for this? is there a kind of convention for this simple CRUD or is it more just do whatever feels right? Also, apologies if this has already been asked or solved, i’ve been looking everywhere for a way to solve this and haven’t seen something on this basic level but this was kinda close

Showing Posts 1 to 3

barnabasJ

barnabasJ

Ash Core Team

You only accept the created_by_user_id at the moment, you also need to accept the partner_id and you probably don’t need to accept the created_by_user_id attribute because you don’t pass that directly but use the actor to set the value.

accept [:created_by_user_id, :partner_id]

You don’t need manage_relationship if you set the ids directly.

There is a section in the getting started guide that shows this, it’s using an update action but otherwise it works the same way Get Started — ash v3.29.3

There is also this section about using manage_relationship Relationships — ash v3.29.3

You can also do everything manage_relationship and more using before/after action hooks.

firesidewing

firesidewing OP

Ah yeah, definitely remember reading those, that works just fine thank you!

Am I still able to use that :* trick in the accept parameters for an action, or the default_accept? It was handy to have but since my create/update actions handle a relationship i don’t think i can do the defaults [:read, :destroy, create: :*, update: :*]

barnabasJ

barnabasJ

Ash Core Team

I think it should work. :* stands for all public attributes, and the belongs_to definition adds a public attribute if the relationship is public.

— All posts loaded —

Where Next? Top

Trending in Questions Top

katta
I having some trouble figuring out if I have set myself too strict of standards for my production server. Currently I can handle 75% of r...
New
brecabral
Documentation While reading the Scoped Routes section, I noticed that the documentation currently refers to a problem without explainin...
New
nseaSeb
Hello, I know there is an approach for handling lists that allows for optimized traversal, but I can’t recall the specific method (somet...
New
kpanic
Hi everyone, I am toying with the idea of building a “match maker” for giving personal help to people that wants to start coding. I sta...
New
velrest
So my question is quite simple and i have found no conclusive answer on forum, google or AI. Should we use :erlang.float for Integer to ...
New
asweet-confluent
I recently noticed that Elixir’s Logger defaults its primary log level to :debug when no :logger, :level application configuration is pre...
New
apz
I’m new to elixir and just tried to install the elixirLS extension for VScode(ium) and it is throwing some errors that I would like help ...
New

Other Trending Topics Top

GenericJam
Edit: 2026 May 15 - This post is archived. Mob is alive!! Main docs: mob v0.7.11 — Documentation A bit of explanation for the slightly c...
New
JesseHerrick
Hey, I’m Jesse and I’m the main contributor behind Dexter, a full-featured, lightning-fast Elixir LSP optimized for large codebases. It s...
New
mudasobwa
I am happy to introduce the very α version of the new programming language compiled to BEAM. Welcome Cure. It has literally three kille...
New
garrison
Hobbes is a low-level distributed database for the Elixir programming language. Hobbes provides a simple, safe, and scalable storage lay...
New
mhanberg
Hi everyone! The first release candidate for the Expert language server project is now available! We’ve published a press release detai...
New
budgie
A little off-topic, but I feel like people here have a good head on their shoulders. I used to be quite good at making software. Was luc...
New

We're in Beta

About us Mission Statement

Options

Thread Display Mode




Thread Preview

Skip Thread Previews