MCPcopy
hub / github.com/sequelize/sequelize / _validateIncludedElement

Method _validateIncludedElement

lib/model.js:587–713  ·  lib/model.js::Model._validateIncludedElement
(include, tableNames, options)

Source from the content-addressed store, hash-verified

585 }
586
587 static _validateIncludedElement(include, tableNames, options) {
588 tableNames[include.model.getTableName()] = true;
589
590 if (include.attributes && !options.raw) {
591 include.model._expandAttributes(include);
592
593 include.originalAttributes = include.model._injectDependentVirtualAttributes(include.attributes);
594
595 include = Utils.mapFinderOptions(include, include.model);
596
597 if (include.attributes.length) {
598 _.each(include.model.primaryKeys, (attr, key) => {
599 class="cm">// Include the primary key if it's not already included - take into account that the pk might be aliased (due to a .field prop)
600 if (!include.attributes.some(includeAttr => {
601 if (attr.field !== key) {
602 return Array.isArray(includeAttr) && includeAttr[0] === attr.field && includeAttr[1] === key;
603 }
604 return includeAttr === key;
605 })) {
606 include.attributes.unshift(key);
607 }
608 });
609 }
610 } else {
611 include = Utils.mapFinderOptions(include, include.model);
612 }
613
614 class="cm">// pseudo include just needed the attribute logic, return
615 if (include._pseudo) {
616 if (!include.attributes) {
617 include.attributes = Object.keys(include.model.tableAttributes);
618 }
619 return Utils.mapFinderOptions(include, include.model);
620 }
621
622 class="cm">// check if the current Model is actually associated with the passed Model - or it's a pseudo include
623 const association = include.association || this._getIncludedAssociation(include.model, include.as);
624
625 include.association = association;
626 include.as = association.as;
627
628 class="cm">// If through, we create a pseudo child include, to ease our parsing later on
629 if (include.association.through && Object(include.association.through.model) === include.association.through.model) {
630 if (!include.include) include.include = [];
631 const through = include.association.through;
632
633 include.through = _.defaults(include.through || {}, {
634 model: through.model,
635 as: through.model.name,
636 association: {
637 isSingleAssociation: true
638 },
639 _pseudo: true,
640 parent: include
641 });
642
643
644 if (through.scope) {

Callers

nothing calls this directly

Calls 5

getTableNameMethod · 0.80
_expandAttributesMethod · 0.80
_injectScopeMethod · 0.80

Tested by

no test coverage detected