Can't get userId to filter

Hey guys :wave:t2:,

So basically I have a table “Family” in Strapi with a column “familyOwner” who have a relation with User.

I provided 3 screenshots and code below. (1 : Screenshot of the familyOwner with User, 2 : Screenshot of the data that is working without the filter query method 3 : the error when adding the filter.)

What I’m trying to achieve is filter the data to not show every rows that are available inside the Family table but only if familyOwner = userId.

I logged the User ID inside the console and I get the right one (17).

I don’t really understand why it doesn’t work, because I wrote right “familyOwner” in my filter method, all the data are published, the access is possible through auth role, it’s only when I add

         familyOwner: {
           id: {
             $eq: userId,
           },
         },
       },```

TO this :

const query = qs.stringify(
{
populate: “*”,
filters: {
familyOwner: {
id: {
$eq: userId,
},
},
},
},
{ encodeValuesOnly: true }
);


<i>This topic has been created from a Discord post (1273550514709073952) to give it more visibility.
It will be on Read-Only mode here.
<a href="https://discord.com/channels/811989166782021633/1273550514709073952/1273550514709073952">Join the conversation on Discord</a></i>

If you need any precision or anything more tell, I know the issue is on the filter part but I can’t figure out why?? I followed the doc here and it seems to be the same : Filters, Locale, and Publication State | Strapi Documentation no?

Here is the complete code if you need :

import { getAuthToken } from "./get-token";
import { getStrapiURL } from "@/lib/utils";
import qs from "qs";

export async function getFamilyMembersLoader() {
  const baseUrl = getStrapiURL();
  const authToken = await getAuthToken();
  if (!authToken) return { ok: false, data: null, error: "No auth token" };

  try {
    const userResponse = await fetch(`${baseUrl}/api/users/me`, {
      headers: {
        Authorization: `Bearer ${authToken}`,
      },
    });
    const userData = await userResponse.json();
    const userId = userData.id;

    console.log("User ID:", userId);

    const query = qs.stringify(
      {
        filters: {
          familyOwner: {
            $eq: userId,
          },
        },
        populate: "*",
      },
      { encodeValuesOnly: true }
    );

    const url = new URL(`${baseUrl}/api/families?${query}`);

    const response = await fetch(url.href, {
      method: "GET",
      headers: {
        "Content-Type": "application/json",
        Authorization: `Bearer ${authToken}`,
      },
      cache: "no-cache",
    });
    const data = await response.json();
    if (data.error) return { ok: false, data: null, error: data.error };
    return { ok: true, data: data.data, error: null };
  } catch (error) {
    console.log(error);
    return { ok: false, data: null, error: error };
  }
}