Ash FrameworkAF
Ash Framework3y ago
10 replies
harry

How to manage `belongs_to` relations

I have this action in my resource
    create :new_token do
      accept([:nickname, :scopes, :system, :expires_at])

      argument :user, Project.Resources.Accounts.User do
        allow_nil?(false)
      end

      change(manage_relationship(:user, on_match: :relate))

      # ...
  end

but when I create a new token, the user and user_id are nil
           |> Ash.Changeset.for_create(:new_token, %{
             user: user,
             system: true,
             scopes: ["read", "write"],
             expires_at:
               DateTime.utc_now()
               |> DateTime.add(@max_age, :second)
               |> DateTime.truncate(:second)
           })
Was this page helpful?