How to use the strapi/lib/configuration/hooks/models/utils/.defineAssociations function in strapi

To help you get started, we’ve selected a few strapi examples, based on popular ways it is used in public projects.

Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.

github strapi / strapi / packages / strapi-bookshelf / lib / index.js View on Github external
_.forEach(definition.attributes, function (details, name) {
            const verbose = _.get(utilsModels.getNature(details, name), 'verbose') || '';

            // Build associations key
            if (!_.isEmpty(verbose)) {
              utilsModels.defineAssociations(globalName, definition, details, name);
            }

            switch (verbose) {
              case 'hasOne':
                const FK = _.findKey(strapi.models[details.model].attributes, function (details) {
                  if (details.hasOwnProperty('model') && details.model === model && details.hasOwnProperty('via') && details.via === name) {
                    return details;
                  }
                });

                loadedModel[name] = function () {
                  return this.hasOne(global[_.capitalize(details.model)], FK);
                };
                break;

              case 'hasMany':

strapi

An open source headless CMS solution to create and manage your own API. It provides a powerful dashboard and features to make your life easier. Databases supported: MongoDB, MySQL, MariaDB, PostgreSQL, SQLite

SEE LICENSE IN LICENSE
Latest version published 1 year ago

Package Health Score

41 / 100
Full package analysis