index.js
function extractFKs(schema) {
	var FKs = {};

	_.forEach(schema.paths, function(path, id) {
		if (id == 'id' || id == '_id') {
			// Pass
		} else if (path.instance && path.instance == 'ObjectID') {
			FKs[id] = {type: FK_OBJECTID};
		} else if (path.caster && path.caster.instance == 'ObjectID') { // Array of ObjectIDs
			FKs[id] = {type: FK_OBJECTID_ARRAY};
		} else if (path.schema) {
			FKs[id] = {
				type: FK_SUBDOC,
				fks: extractFKs(path.schema),
			};
		}
	});

	return FKs;
}
function extractFKs(schema) {
	var FKs = {};

	_.forEach(schema.paths, function(path, id) {
		if (id == 'id' || id == '_id') {
			// Pass
		} else if (path.instance && path.instance == 'ObjectID') {
			FKs[id] = {type: FK_OBJECTID};
		} else if (path.caster && path.caster.instance == 'ObjectID') { // Array of ObjectIDs
			FKs[id] = {type: FK_OBJECTID_ARRAY};
		} else if (path.schema) {
			FKs[id] = {
				type: FK_SUBDOC,
				fks: extractFKs(path.schema),
			};
		}
	});

	return FKs;
}
function extractFKs ( schema ) { var FKs = { } ; _ . forEach ( schema . paths , function ( path , id ) { if ( id == 'id' || id == '_id' ) { // Pass } else if ( path . instance && path . instance == 'ObjectID' ) { FKs [ id ] = { type : FK_OBJECTID } ; } else if ( path . caster && path . caster . instance == 'ObjectID' ) { // Array of ObjectIDs FKs [ id ] = { type : FK_OBJECTID_ARRAY } ; } else if ( path . schema ) { FKs [ id ] = { type : FK_SUBDOC , fks : extractFKs ( path . schema ) , } ; } } ) ; return FKs ; }
Extract the FK relationship from a Mongo document
@param {Object} schema The schema object to examine (usually connection.base.models[model].schema)
@return {Object} A dictionary of foreign keys for the schema
Extract the FK relationship from a Mongo document