controllers/Match.js
function afterFindMatch(models){
		if(models.length != 1) return next(404);

		model = models[0];

		// Fetch Both Teams
		app.models.Team.findById(model.teamAId).exec(function(err, models){
			model.teamA = models.length ? models[0] : null;
			checkFetch();
		});

		app.models.Team.findById(model.teamBId).exec(function(err, models){
			model.teamB = models.length ? models[0] : null;
			checkFetch();
		});

		// Fetch Group
		app.models.Group.findById(model.groupId).exec(function(err, models){
			model.group = models.length ? models[0] : null;
			checkFetch();
		});
	}
function afterFindMatch(models){
		if(models.length != 1) return next(404);

		model = models[0];

		// Fetch Both Teams
		app.models.Team.findById(model.teamAId).exec(function(err, models){
			model.teamA = models.length ? models[0] : null;
			checkFetch();
		});

		app.models.Team.findById(model.teamBId).exec(function(err, models){
			model.teamB = models.length ? models[0] : null;
			checkFetch();
		});

		// Fetch Group
		app.models.Group.findById(model.groupId).exec(function(err, models){
			model.group = models.length ? models[0] : null;
			checkFetch();
		});
	}
function afterFindMatch ( models ) { if ( models . length != 1 ) return next ( 404 ) ; model = models [ 0 ] ; // Fetch Both Teams app . models . Team . findById ( model . teamAId ) . exec ( function ( err , models ) { model . teamA = models . length ? models [ 0 ] : null ; checkFetch ( ) ; } ) ; app . models . Team . findById ( model . teamBId ) . exec ( function ( err , models ) { model . teamB = models . length ? models [ 0 ] : null ; checkFetch ( ) ; } ) ; // Fetch Group app . models . Group . findById ( model . groupId ) . exec ( function ( err , models ) { model . group = models . length ? models [ 0 ] : null ; checkFetch ( ) ; } ) ; }
Called after match is fetched. Associate with Group and Teams
Called after match is fetched . Associate with Group and Teams