Get relation data

  • I have like this “GameSession” data

  • here “gameCatalogueId” contain data of “GameCatalogue” table data

  • “gameCatalogueId” have one “GameCatalogue” table data

  • this data seen in parse dashbord but when i want get those data using API its not provide all data

    const fetchData = async () => {
        // Create a new Parse Query
        const GameSession = Parse.Object.extend('GameSession');
        const query = new Parse.Query(GameSession);

        try {
            // Execute the query to retrieve all records
            const results = await query.find();
            // console.log("===", results);

            // Loop through each GameSession to get related GameCatalogue data
            for (const session of results) {
                const relation = session.relation('GAMECATALOGUE'); // Get the relation

                const gameCatalogueQuery = relation.query(); // Create query for the relation

                const gameCatalogues = await gameCatalogueQuery.find(); // Fetch related GameCatalogue

                console.log("===", gameCatalogues);


                // Map and log session and game catalogue details
                const sessionData = gameCatalogues.map((game) => ({
                    sessionId: session.id,
                    gameCatalogueId: game.id,
                    gameName: game.get('name'),
                }));

                console.log(sessionData);
            }

        } catch (error) {
            console.error('Error while fetching data:', error);
        }
    };

  • Need data of most played games

@dhyan
You can include specifically, which field you want to include.

for ex,
query.include('*');

If I understood it, that could solve this problem.

I used in .include but for this scenario its not working for me.

Did you check what data is coming before gameCatalogues .map code?

yes thats work fine for me