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

Method _expandIncludeAllElement

lib/model.js:396–496  ·  view source on GitHub ↗
(includes, include)

Source from the content-addressed store, hash-verified

394 }
395
396 static _expandIncludeAllElement(includes, include) {
397 // check 'all' attribute provided is valid
398 let all = include.all;
399 delete include.all;
400
401 if (all !== true) {
402 if (!Array.isArray(all)) {
403 all = [all];
404 }
405
406 const validTypes = {
407 BelongsTo: true,
408 HasOne: true,
409 HasMany: true,
410 One: ['BelongsTo', 'HasOne'],
411 Has: ['HasOne', 'HasMany'],
412 Many: ['HasMany']
413 };
414
415 for (let i = 0; i < all.length; i++) {
416 const type = all[i];
417 if (type === 'All') {
418 all = true;
419 break;
420 }
421
422 const types = validTypes[type];
423 if (!types) {
424 throw new sequelizeErrors.EagerLoadingError(`include all '${type}' is not valid - must be BelongsTo, HasOne, HasMany, One, Has, Many or All`);
425 }
426
427 if (types !== true) {
428 // replace type placeholder e.g. 'One' with its constituent types e.g. 'HasOne', 'BelongsTo'
429 all.splice(i, 1);
430 i--;
431 for (let j = 0; j < types.length; j++) {
432 if (!all.includes(types[j])) {
433 all.unshift(types[j]);
434 i++;
435 }
436 }
437 }
438 }
439 }
440
441 // add all associations of types specified to includes
442 const nested = include.nested;
443 if (nested) {
444 delete include.nested;
445
446 if (!include.include) {
447 include.include = [];
448 } else if (!Array.isArray(include.include)) {
449 include.include = [include.include];
450 }
451 }
452
453 const used = [];

Callers 1

_expandIncludeAllMethod · 0.95

Calls

no outgoing calls

Tested by

no test coverage detected