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