MCPcopy
hub / github.com/sequelize/sequelize / _expandIncludeAllElement

Method _expandIncludeAllElement

src/model.js:419–519  ·  view source on GitHub ↗
(includes, include)

Source from the content-addressed store, hash-verified

417 }
418
419 static _expandIncludeAllElement(includes, include) {
420 // check 'all' attribute provided is valid
421 let all = include.all;
422 delete include.all;
423
424 if (all !== true) {
425 if (!Array.isArray(all)) {
426 all = [all];
427 }
428
429 const validTypes = {
430 BelongsTo: true,
431 HasOne: true,
432 HasMany: true,
433 One: ['BelongsTo', 'HasOne'],
434 Has: ['HasOne', 'HasMany'],
435 Many: ['HasMany']
436 };
437
438 for (let i = 0; i < all.length; i++) {
439 const type = all[i];
440 if (type === 'All') {
441 all = true;
442 break;
443 }
444
445 const types = validTypes[type];
446 if (!types) {
447 throw new sequelizeErrors.EagerLoadingError(`include all '${type}' is not valid - must be BelongsTo, HasOne, HasMany, One, Has, Many or All`);
448 }
449
450 if (types !== true) {
451 // replace type placeholder e.g. 'One' with its constituent types e.g. 'HasOne', 'BelongsTo'
452 all.splice(i, 1);
453 i--;
454 for (let j = 0; j < types.length; j++) {
455 if (!all.includes(types[j])) {
456 all.unshift(types[j]);
457 i++;
458 }
459 }
460 }
461 }
462 }
463
464 // add all associations of types specified to includes
465 const nested = include.nested;
466 if (nested) {
467 delete include.nested;
468
469 if (!include.include) {
470 include.include = [];
471 } else if (!Array.isArray(include.include)) {
472 include.include = [include.include];
473 }
474 }
475
476 const used = [];

Callers 1

_expandIncludeAllMethod · 0.95

Calls

no outgoing calls

Tested by

no test coverage detected