Adding an association in an action based on argument
Hey, been a few minutes since I've done any work on an Ash project, hoping someone can jog my memory on how to accomplish something.
Basically, I've got two resources,
Thanks!
Maps.Map and Pin , where a Pin belongs to a Map. I want to pass an existing Map to the Pin as part of the create action. like so
Been searching the docs, but I can't really figure out how to take my argument and add the association
I was thinking it's something like using change like so, but not quite
Thanks!
4 Replies
you should use manage_relationship 🙂
if you want to use the set_attribute directly, I think you need to uhh, set the attribute to be
public?: true, and writeable?: true, it's recommended to use this instead https://hexdocs.pm/ash/relationships.html#managing-relationshipsI thought
manage_relationship is for creating instances of the other relationship
Like if I wanted to create one or more Pins by passing a list of them to the Map action
Maybe I'm just approaching it from the wrong side
Okay, I think I've got it
yeah the type / on lookup things can be a bit confusing / annoying
try type: :append_and_remove for existing thing
This should also work.
the
arg helper just returns {:__arg, :arg_name} which is then substituted by ash with the actual value, but .id doesn't work on that.
manage_relationship is doing a bit more work for you, in cases where you need it and it also is useful for extenstions like ash_graphql, they check those to create a type for the :map argument for example