How to use strapi-bookshelf - 3 common examples

To help you get started, we’ve selected a few strapi-bookshelf 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-generate-migrations / lib / builder / relations.js View on Github external
// Otherwise if it's a "many-to-many" relationship.

      // Save the relationship.
      const relationship = models[details.collection].attributes[details.via];

      // Construct relation table name.
      const relationTable = _.map(_.sortBy([relationship, details], 'collection'), table => {
        return _.snakeCase(pluralize.plural(table.collection) + ' ' + pluralize.plural(table.via));
      }).join('__');

      // Force singular foreign key.
      relationship.attribute = pluralize.singular(relationship.collection);
      details.attribute = pluralize.singular(details.collection);

      // Define PK column.
      details.column = utilsBookShelf.getPK(modelName, undefined, models);
      relationship.column = utilsBookShelf.getPK(details.collection, undefined, models);

      // Avoid to create table both times.
      if (!rootModels.hasOwnProperty(relationTable) || !_.isEmpty(_.get(rootModels, relationTable + '.up.drop'))) {
        // Set objects
        if (_.isUndefined(_.get(models, relationTable + '.up.others'))) {
          _.set(rootModels, relationTable + '.up.others', '');
        }

        if (_.isUndefined(_.get(rootModels, relationTable + '.up.drop'))) {
          _.set(rootModels, relationTable + '.up.drop', '');
        }

        if (_.isUndefined(_.get(rootModels, relationTable + '.down.others'))) {
          _.set(rootModels, relationTable + '.down.others', '');
        }
github strapi / strapi / packages / strapi-generate-migrations / lib / builder / relations.js View on Github external
}

    if (_.isEmpty(_.get(rootModels[modelName].attributes, attribute + '.delete'))) {
      _.set(rootModels[modelName].attributes, attribute + '.delete', {
        drop: '',
        others: ''
      });
    }

    // If it's a "one-to-one" relationship.
    if (infos.verbose === 'hasOne') {
      // Force singular foreign key.
      details.attribute = pluralize.singular(details.model);

      // Define PK column.
      details.column = utilsBookShelf.getPK(modelName, undefined, models);

      if (!toDrop) {
        tplRelationUp = fs.readFileSync(path.resolve(__dirname, '..', '..', 'templates', 'builder', 'relations', 'hasOne.template'), 'utf8');
        models[modelName].attributes[attribute].create.others += _.unescape(_.template(tplRelationUp)({
          tableName: modelName,
          attribute,
          details
        }));

        tplRelationDown = fs.readFileSync(path.resolve(__dirname, '..', '..', 'templates', 'builder', 'columns', 'dropColumn-unique.template'), 'utf8');
        models[modelName].attributes[attribute].delete.others += _.unescape(_.template(tplRelationDown)({
          tableName: modelName,
          attribute,
          details
        }));
      } else {
github strapi / strapi / packages / strapi-generate-migrations / lib / builder / relations.js View on Github external
// Save the relationship.
      const relationship = models[details.collection].attributes[details.via];

      // Construct relation table name.
      const relationTable = _.map(_.sortBy([relationship, details], 'collection'), table => {
        return _.snakeCase(pluralize.plural(table.collection) + ' ' + pluralize.plural(table.via));
      }).join('__');

      // Force singular foreign key.
      relationship.attribute = pluralize.singular(relationship.collection);
      details.attribute = pluralize.singular(details.collection);

      // Define PK column.
      details.column = utilsBookShelf.getPK(modelName, undefined, models);
      relationship.column = utilsBookShelf.getPK(details.collection, undefined, models);

      // Avoid to create table both times.
      if (!rootModels.hasOwnProperty(relationTable) || !_.isEmpty(_.get(rootModels, relationTable + '.up.drop'))) {
        // Set objects
        if (_.isUndefined(_.get(models, relationTable + '.up.others'))) {
          _.set(rootModels, relationTable + '.up.others', '');
        }

        if (_.isUndefined(_.get(rootModels, relationTable + '.up.drop'))) {
          _.set(rootModels, relationTable + '.up.drop', '');
        }

        if (_.isUndefined(_.get(rootModels, relationTable + '.down.others'))) {
          _.set(rootModels, relationTable + '.down.others', '');
        }

strapi-bookshelf

Bookshelf hook for the Strapi framework

MIT
Latest version published 8 years ago

Package Health Score

60 / 100
Full package analysis

Popular strapi-bookshelf functions