Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.
_.forEach(definition.attributes, (details, name) => {
const verbose = _.get(utilsModels.getNature(details, name, undefined, model.toLowerCase()), 'verbose') || '';
// Build associations key
utilsModels.defineAssociations(model.toLowerCase(), definition, details, name);
if (_.isEmpty(verbose)) {
definition.loadedModel[name].type = utils(instance).convertType(details.type);
}
switch (verbose) {
case 'hasOne': {
const ref = details.plugin ? strapi.plugins[details.plugin].models[details.model].globalId : strapi.models[details.model].globalId;
definition.loadedModel[name] = {
type: instance.Schema.Types.ObjectId,
ref
};
break;
}
case 'hasMany': {
_.forEach(definition.attributes, (details, name) => {
const verbose = _.get(
utilsModels.getNature(details, name, undefined, model.toLowerCase()),
'verbose'
) || '';
// Build associations key
utilsModels.defineAssociations(
model.toLowerCase(),
definition,
details,
name
);
let globalId;
const globalName = details.model || details.collection || '';
// Exclude polymorphic association.
if (globalName !== '*') {
globalId = details.plugin ?
_.get(strapi.plugins,`${details.plugin}.models.${globalName.toLowerCase()}.globalId`):
_.get(strapi.models, `${globalName.toLowerCase()}.globalId`);
}
const buildRelation = ({ definition, model, instance, attribute, name }) => {
const { nature, verbose } =
utilsModels.getNature(attribute, name, undefined, model.toLowerCase()) ||
{};
// Build associations key
utilsModels.defineAssociations(
model.toLowerCase(),
definition,
attribute,
name
);
switch (verbose) {
case 'hasOne': {
const ref = attribute.plugin
? strapi.plugins[attribute.plugin].models[attribute.model].globalId
: strapi.models[attribute.model].globalId;
definition.loadedModel[name] = {
type: instance.Schema.Types.ObjectId,
ref,
};
Object.keys(definition.attributes).forEach(name => {
const details = definition.attributes[name];
if (details.type !== undefined) {
return;
}
const { nature, verbose } =
utilsModels.getNature(details, name, undefined, model.toLowerCase()) ||
{};
// Build associations key
utilsModels.defineAssociations(
model.toLowerCase(),
definition,
details,
name
);
let globalId;
const globalName = details.model || details.collection || '';
// Exclude polymorphic association.
if (globalName !== '*') {
globalId = details.plugin
? _.get(
strapi.plugins,
`${details.plugin}.models.${globalName.toLowerCase()}.globalId`
)
_.forEach(definition.attributes, (details, name) => {
const verbose = _.get(utilsModels.getNature(details, name, undefined, model.toLowerCase()), 'verbose') || '';
// Build associations key
utilsModels.defineAssociations(model.toLowerCase(), definition, details, name);
if (_.isEmpty(verbose)) {
definition.loadedModel[name].type = utils(instance).convertType(details.type);
}
switch (verbose) {
case 'hasOne': {
const ref = details.plugin ? strapi.plugins[details.plugin].models[details.model].globalId : strapi.models[details.model].globalId;
definition.loadedModel[name] = {
type: instance.Schema.Types.ObjectId,
ref
};
break;
}
case 'hasMany': {