SupabaseS
Supabase4y ago
urth

Limit the rows from inner joined table

Hi,

Is there a way to limit the amount of the records I can get from the joined table?

export async function getUserWithAllRelatons(username: string, supabase: SupabaseClient){
    let user = await supabase.from('users').select(`
    id,
    username,
    email,
    created_at,
    stats (
        *
    ),
    friends!friends_user_id_fkey (
        friend_id
    )
    `).eq('username', username).single()
    
    if(user.error){
        return null;
    }

    return user.data as Partial<User>;
}


As a single user can have many friends, I would like to limit the amount of friends to lets say 50

{
username: ...
password:...
friends: [ Array with length < 50 ]
}

EDIT: I'm not sure if this is even possible... Thinking of adding additional field inside friends which would help me make the query.
Was this page helpful?