Back

AppwriteException: Invalid relationship value. Must be either a document ID or a document, array giv

  • 0
  • Self Hosted
  • Web
Misho
28 Jul, 2024, 10:40

I am updating user, more correctly i am update user profile image of user and i get this error:

TypeScript
  code: 400,
  type: 'relationship_value_invalid',
  response: {
    message: 'Invalid relationship value. Must be either a document ID or a document, array given.',
    code: 400,
    type: 'relationship_value_invalid',
    version: '1.5.7'
  }
}
TL;DR
Developers are encountering an error when updating a user profile image due to an "Invalid relationship value" message. The issue lies in passing an array instead of a document ID. To resolve this, ensure the correct data type is provided as the relationship value when updating the user profile image.
Misho
28 Jul, 2024, 10:51

@Steven

Misho
28 Jul, 2024, 10:52

Is there any work around

Misho
28 Jul, 2024, 10:52

here

Misho
28 Jul, 2024, 10:52
TypeScript
"use server";

import {
  createSessionClient,
} from "@/lib/utils/appwrite-server";
import { envi } from "@/lib/utils/env";
import { User } from "../../types";
import { updateUserSchema } from "./update-user.schema";
import {  Query } from "node-appwrite";
import { revalidatePath } from "next/cache";

export default async function updateUser(
  id: User["$id"],
  values: unknown
) {
  try {
    const res = updateUserSchema.parse(values);
    const { databases, teams } = await createSessionClient();

    try {
      const membership = await teams.listMemberships(
        envi.NEXT_PUBLIC_NEW_USERS_TEAM_ID,
        [Query.equal("userId", id)]
      );

      if (membership.total > 0) {
        const membershipId = membership.memberships[0].$id;
        await teams.deleteMembership(
          envi.NEXT_PUBLIC_NEW_USERS_TEAM_ID,
          membershipId
        );
      }
    } catch (error) {}
    
    await databases.updateDocument(
      envi.NEXT_PUBLIC_HOPPLA_DATABASE_ID,
      envi.NEXT_PUBLIC_USERS_COLLECTION_ID,
      id,
      res
    );
    revalidatePath("/");
    return {};
  } catch (error) {
    console.error(error)
    return {
      error: "An unexpected error occurred when updating user",
    };
  }
}
Misho
28 Jul, 2024, 10:52

@შონია

Reply

Reply to this thread by joining our Discord

Reply on Discord

Need support?

Join our Discord

Get community support by joining our Discord server.

Join Discord

Get premium support

Join Appwrite Pro and get email support from our team.

Learn more