https://supabase.com/ logo
Join DiscordCommunities
Powered by
# help
  • f

    Flyken

    07/27/2021, 7:45 PM
    yea
  • f

    frubalu

    07/27/2021, 7:46 PM
    could you show me your
    fetchGames()
    method again? might be able to simplify this quite a bit
  • f

    Flyken

    07/27/2021, 7:46 PM
    Copy code
    js
    const fetchGames = async () => {
        if (!user) return;
        return await supabase.from('users_games').select().eq('user_id', user.id);
      };
  • f

    frubalu

    07/27/2021, 7:47 PM
    supabase.from('users_games').select('*, games(*)').eq('user_id', user.id);
  • f

    frubalu

    07/27/2021, 7:47 PM
    try something like that
  • f

    Flyken

    07/27/2021, 7:48 PM
    :O
  • f

    frubalu

    07/27/2021, 7:48 PM
    you're trying to query table relationships: https://supabase.io/docs/postgrest/client/select#query-foreign-tables
  • f

    Flyken

    07/27/2021, 7:48 PM
    its got a new object on it
  • f

    Flyken

    07/27/2021, 7:48 PM
    games
  • f

    Flyken

    07/27/2021, 7:48 PM
    sorry if im seeming super noob on this
  • f

    frubalu

    07/27/2021, 7:48 PM
    all good
  • f

    frubalu

    07/27/2021, 7:49 PM
    does that nested object have the data that you're looking for?
  • f

    frubalu

    07/27/2021, 7:49 PM
    if it does, great. this will prevent you from making potentially dozens of db queries
  • f

    Flyken

    07/27/2021, 7:49 PM
    yea, it does :)
  • f

    frubalu

    07/27/2021, 7:49 PM
    awesome!
  • f

    frubalu

    07/27/2021, 7:50 PM
    then you can always iterate over that data to set it to state if that's easier
  • f

    Flyken

    07/27/2021, 7:50 PM
    ok so my question now
  • f

    Flyken

    07/27/2021, 7:51 PM
    i have
    const [games, setGames] = useState([])
    right
  • f

    Flyken

    07/27/2021, 7:51 PM
    how do i put these objects into that as an array?
  • f

    frubalu

    07/27/2021, 7:52 PM
    what's your response look like from
    fetchGames()
    ?
  • f

    Flyken

    07/27/2021, 7:52 PM
    oh wait
  • f

    Flyken

    07/27/2021, 7:52 PM
    i see
  • f

    Flyken

    07/27/2021, 7:53 PM
    if i console log
    game.games
    , it returns the right thing
  • f

    Flyken

    07/27/2021, 7:53 PM
    just as seperate logs
  • f

    frubalu

    07/27/2021, 7:54 PM
    so you'd probably run something like:
    Copy code
    setGames(prev => [...prev, newGame ])
  • f

    Flyken

    07/27/2021, 7:55 PM
    AAAYYYEEE
  • f

    Flyken

    07/27/2021, 7:55 PM
    i think it works
  • f

    Flyken

    07/27/2021, 7:56 PM
    yea
  • f

    Flyken

    07/27/2021, 7:56 PM
    it works :)
  • f

    Flyken

    07/27/2021, 7:56 PM
    thanks a bunch
1...91011...316Latest