Back

AppwriteException: Invalid relationship value.

  • 0
  • Web
BelairBeats
20 May, 2024, 17:14

my name is Nico and I am new to development, nevertheless I will try my best to make this as streamlines as possible.

Important to know is that i use the same code for "likes", and "events", "bars", "groups". It still works for "likes" but the program stopped working since the update on 30th april for the other 3 cases. I will post the segments to "likes" and "events" below so one can see that there are no differences.

I followed this tutorial to get the baseline of my code. https://www.youtube.com/watch?v=_W3R2VwRyF4&t=6611s

  1. Project ID: 65a033873cf893718c5e
  2. Error 1: "PATCH https://cloud.appwrite.io/v1/databases/65a0475331c0192aa8ed/collections/65ab8d3ff190c144ff4f/documents/65ad6c02b5ec448e65e5 400 (Bad Request)"

followed by Error 2: "AppwriteException: Invalid relationship value. Must be either an array of documents or document IDs, NULL given."

  1. The error points to the following segments: "api.ts / querriesAndMutations.ts / eventStats.ts

Thanks in advance for your help. Me and my team are really struggeling to find the issue. Since it was once working and "likes" is still working it makes it even more strange...

TL;DR
The developer is encountering the error "AppwriteException: Invalid relationship value" in their application when trying to update relationships for "events". This issue occurred after an update on April 30th. The same code is used for "likes" and "events", and while "likes" is still functioning properly, the problem persists for other cases. The error is related to the API files, queries and mutations, and event stats files. Additionally, they provided the Project ID as 65a033873cf893718c5e. The error messages received are "PATCH https://cloud.appwrite.io/v1/databases/65a047
BelairBeats
20 May, 2024, 17:14

HERE THE CODE:

**CODE FOR "EVENTS: ** API FILE export async function participantEvent(eventId: string, participantArray: string[]) { try { const updatedEvent = await databases.updateDocument( appwriteConfig.databaseId, appwriteConfig.eventCollectionId, eventId, { participant: participantArray, } );

TypeScript
    if (!updatedEvent) throw Error;

    return updatedEvent;
  } catch (error) {
    console.error(error);
  }
}

QUERRIESANDMUTATION export const useParticipantEvent = () => { const queryClient = useQueryClient();

TypeScript
  return useMutation({
    mutationFn: ({ eventId, participantArray }: { eventId: string; participantArray: string[]; }) =>
      participantEvent(eventId, participantArray),
    onSuccess: (data) => {
      queryClient.invalidateQueries({
        queryKey: [QUERY_KEYS.GET_EVENT_BY_ID, data?.$id],
      });
      queryClient.invalidateQueries({
        queryKey: [QUERY_KEYS.GET_RECENT_EVENTS],
      });
      queryClient.invalidateQueries({
        queryKey: [QUERY_KEYS.GET_EVENTS],
      });
      queryClient.invalidateQueries({
        queryKey: [QUERY_KEYS.GET_CURRENT_USER],
      });
    },
  });
};

EVENTSTATS FILE const handleParticipantEvent = ( e: React.MouseEvent<HTMLImageElement, MouseEvent> ) => { e.stopPropagation();

TypeScript
    let participantArray = [...participants];

    if (participantArray.includes(userId)) {
      participantArray = participantArray.filter((Id) => Id !== userId);
    } else {
      participantArray.push(userId);
    }

    setParticipants(participantArray);
    participantEvent({ eventId: event.$id, participantArray });

    // Redirect to "groups" page
    navigate('/groups');
  };
BelairBeats
20 May, 2024, 17:14

CODE FOR "LIKES": API FILE export async function likePost(postId: string, likesArray: string[]) { try { const updatedPost = await databases.updateDocument( appwriteConfig.databaseId, appwriteConfig.postCollectionId, postId, { likes: likesArray, } );

TypeScript
  if (!updatedPost) throw Error;

  return updatedPost;
} catch (error) {
  console.log(error);
}

}

QUERRIESANDMUTATION export const useLikePost = () => { const queryClient = useQueryClient(); return useMutation({ mutationFn: ({ postId, likesArray, }: { postId: string; likesArray: string[]; }) => likePost(postId, likesArray), onSuccess: (data) => { queryClient.invalidateQueries({ queryKey: [QUERY_KEYS.GET_POST_BY_ID, data?.$id], }); queryClient.invalidateQueries({ queryKey: [QUERY_KEYS.GET_RECENT_POSTS], }); queryClient.invalidateQueries({ queryKey: [QUERY_KEYS.GET_POSTS], }); queryClient.invalidateQueries({ queryKey: [QUERY_KEYS.GET_CURRENT_USER], }); }, }); };

POSTSTATS FILE const handleLikePost = ( e: React.MouseEvent<HTMLImageElement, MouseEvent> ) => { e.stopPropagation();

TypeScript
    let likesArray = [...likes];

    if (likesArray.includes(userId)) {
      likesArray = likesArray.filter((Id) => Id !== userId);
    } else {
      likesArray.push(userId);
    }

    setLikes(likesArray);
    likePost({ postId: post.$id, likesArray });
  };
BelairBeats
20 May, 2024, 17:18

AppwriteException: Invalid relationship value.

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