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

Method _validateIncludedElement

src/model.js:610–736  ·  view source on GitHub ↗
(include, tableNames, options)

Source from the content-addressed store, hash-verified

608 }
609
610 static _validateIncludedElement(include, tableNames, options) {
611 tableNames[include.model.getTableName()] = true;
612
613 if (include.attributes && !options.raw) {
614 include.model._expandAttributes(include);
615
616 include.originalAttributes = include.model._injectDependentVirtualAttributes(include.attributes);
617
618 include = Utils.mapFinderOptions(include, include.model);
619
620 if (include.attributes.length) {
621 _.each(include.model.primaryKeys, (attr, key) => {
622 // Include the primary key if it's not already included - take into account that the pk might be aliased (due to a .field prop)
623 if (!include.attributes.some(includeAttr => {
624 if (attr.field !== key) {
625 return Array.isArray(includeAttr) && includeAttr[0] === attr.field && includeAttr[1] === key;
626 }
627 return includeAttr === key;
628 })) {
629 include.attributes.unshift(key);
630 }
631 });
632 }
633 } else {
634 include = Utils.mapFinderOptions(include, include.model);
635 }
636
637 // pseudo include just needed the attribute logic, return
638 if (include._pseudo) {
639 if (!include.attributes) {
640 include.attributes = Object.keys(include.model.tableAttributes);
641 }
642 return Utils.mapFinderOptions(include, include.model);
643 }
644
645 // check if the current Model is actually associated with the passed Model - or it's a pseudo include
646 const association = include.association || this._getIncludedAssociation(include.model, include.as);
647
648 include.association = association;
649 include.as = association.as;
650
651 // If through, we create a pseudo child include, to ease our parsing later on
652 if (include.association.through && Object(include.association.through.model) === include.association.through.model) {
653 if (!include.include) include.include = [];
654 const through = include.association.through;
655
656 include.through = _.defaults(include.through || {}, {
657 model: through.model,
658 as: through.model.name,
659 association: {
660 isSingleAssociation: true
661 },
662 _pseudo: true,
663 parent: include
664 });
665
666
667 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