Many_to_many on email destination
I'm try to create a many to may relationship between a workspace and a user, using user email instead of the user id. But when i try to create the a WorkspaceUser I get an error:
The relation in Workspace is
In WorkspaceUser The action that throw the error is
In WorkspaceUser The action that throw the error is
9 Replies
is the action on the
WorkspaceUser
? If so the email/workspace_id
are just attributes and you don't need the manage_relationship stuff.
Most of the times the argument you would pass to manage_relationship would be a map with the attributes of the related resource.
If you wan't to only manage a single attribute you would need to specify :value_is_key
in the optsyou can find this here in the docs https://ash-hq.org/docs/module/ash/latest/ash-changeset#function-manage_relationship-4
if the action is ment to create a new user you would do somthing like this
and you would also have the relationship declared on the user same as the workspace
That sounds like the correct approach to me 🙂
Thank you very much.
I changed the assign action and add the relation to user but I'm still get this error:
I'm trying to use email instead of user id so that I can invite users to the workspace even if they are not yet registered. Is this the right approach to achieve this?
Hard to say really. You might want to go about it by creating an invitations resource and then hooking into the registration logic to add a user to any workspaces they have an invitation for
What I might suggest is to roll your own behavior in this instance instead of using
manage_relationship
because then you can do something like lookup the user by email and if they exist add them to the workspace, and if they don't create an invite for that email address connected to that workspaceThanks i will try that path. But do you know why I'm getting this error?
and if i do
i get
Because the argument you specify is passed to the related resources appropriate action e.g. create. And you always need to pass a Params map when calling e.g.
Ash.Changset.for_create(:create, %{}=argument, opts)
You need to specify the relationships on the resource.thanks