Parse.com select from join table

Just wondering if I'm doing it right or if there is a better way.

I have 3 tables, Game, User and UserGame . UserGame is a connection table with pointers to game and user tables.

The following script returns all the games the user has joined.

var Game = Parse.Object.extend("Game");
var UserGame = Parse.Object.extend("UserGame");

var innerQuery = new Parse.Query(Game);

var query = new Parse.Query(UserGame);
query.equalTo("user", user);
query.matchesQuery("game", innerQuery);
query.include("game");
query.find({

Now I am trying to return games that the user has not joined. I tried the reverse request above, but it does not work. Any ideas?

There is also a better solution than using the connection table above, should I just add a list of game pointers to the user table?

+3
source share
2 answers

This is useful (and not easily accessible from the website).

https://parse.com/docs/js/symbols/Parse.Query.html

, , .noContainerIn([results of the first query]) .doesNotMatchKeyInQuery

matchesKeyInQuery BTW

+2

, . , , :

1.Build Game, , :

var Game = Parse.Object.extend("Game");
    var query = new Parse.Query(Game);
    query.find({
      success: function(arrayGames) { 
       //store this array to manage later
      },
      error: function(user, error) {
            alert("There is not stored games");
            }
    });

2. , , UserGame, :

var UserGame = Parse.Object.extend("UserGame");
    var query = new Parse.Query(UserGame);
var currentUser = Parse.User.current();
var currentGame;
for(var i=0; i<arrayGames.length ;i++){
 currentGame=arrayGames[i];
 query.equalTo("Game", currentGame);
 query.notEqualTo("User", currentUser);
  query.find({
      success: function(foundGames) {
      //you have got an array with the games not joined to this user 
      },
       error: function(user, error) {
            alert("There are not joined games ");
                }
    });
}

, , , ;)

+1

All Articles