src/middleware/orm.js
function makerelation (model, relation) {
	let options = {
		as: relation.As,
		foreignKey: relation.key
	};
	let target = exp.databases[inflector.pluralize(relation.Children)];
	if (relation.Rel !== 'manyToMany') {
		exp.databases[model][relation.Rel](target, options);
	} else {
		exp.databases[model].prototype.many2many = exp.databases[model].prototype.many2many || {};
		exp.databases[model].prototype.many2many[relation.Parent] = function (id, id2) {
			if (id && id2) {
				return exp.databases[relation.Children].findcre({
					[`${model}ID`]: id,
					[`${relation.Parent}ID`]: id2
				});
			}
			return exp.databases[relation.Children].find({
				where: {
					[`${model}ID`]: id
				}
			}).then(records => {
				let all = [];
				for (const record of records) {
					all.push(exp.databases[relation.Parent].findById(record[`${relation.Parent}ID`]));
				}
				return Promise.all(all);
			});
		};
	}
}
function makerelation (model, relation) {
	let options = {
		as: relation.As,
		foreignKey: relation.key
	};
	let target = exp.databases[inflector.pluralize(relation.Children)];
	if (relation.Rel !== 'manyToMany') {
		exp.databases[model][relation.Rel](target, options);
	} else {
		exp.databases[model].prototype.many2many = exp.databases[model].prototype.many2many || {};
		exp.databases[model].prototype.many2many[relation.Parent] = function (id, id2) {
			if (id && id2) {
				return exp.databases[relation.Children].findcre({
					[`${model}ID`]: id,
					[`${relation.Parent}ID`]: id2
				});
			}
			return exp.databases[relation.Children].find({
				where: {
					[`${model}ID`]: id
				}
			}).then(records => {
				let all = [];
				for (const record of records) {
					all.push(exp.databases[relation.Parent].findById(record[`${relation.Parent}ID`]));
				}
				return Promise.all(all);
			});
		};
	}
}
function makerelation ( model , relation ) { let options = { as : relation . As , foreignKey : relation . key } ; let target = exp . databases [ inflector . pluralize ( relation . Children ) ] ; if ( relation . Rel !== 'manyToMany' ) { exp . databases [ model ] [ relation . Rel ] ( target , options ) ; } else { exp . databases [ model ] . prototype . many2many = exp . databases [ model ] . prototype . many2many || { } ; exp . databases [ model ] . prototype . many2many [ relation . Parent ] = function ( id , id2 ) { if ( id && id2 ) { return exp . databases [ relation . Children ] . findcre ( { [ ` ${ model } ` ] : id , [ ` ${ relation . Parent } ` ] : id2 } ) ; } return exp . databases [ relation . Children ] . find ( { where : { [ ` ${ model } ` ] : id } } ) . then ( records => { let all = [ ] ; for ( const record of records ) { all . push ( exp . databases [ relation . Parent ] . findById ( record [ ` ${ relation . Parent } ` ] ) ) ; } return Promise . all ( all ) ; } ) ; } ; } }
This function extends the CaminteJS relations, adding Many to Many support
This function extends the CaminteJS relations adding Many to Many support