How to use the strapi-utils.models function in strapi-utils

To help you get started, we’ve selected a few strapi-utils 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
'use strict';

/**
 * Module dependencies
 */

// Node.js core.
const fs = require('fs');
const path = require('path');

// Public node modules.
const _ = require('lodash');
const pluralize = require('pluralize');

// Collections utils.
const utilsModels = require('strapi-utils').models;
const utilsBookShelf = require('strapi-bookshelf/lib/utils/');

// Template builder.
const selectTable = require('./selectTable');

/**
 * Relationship templates
 */

module.exports = (rootModels, modelName, details, attribute, toDrop, onlyDrop, history) => {
  let tplRelationUp;
  let tplRelationDown;
  let infos = {};
  let oldInfos = {};

  if (!onlyDrop && toDrop) {
github strapi / strapi / packages / strapi-connector-mongoose / lib / mount-models.js View on Github external
'use strict';

const _ = require('lodash');
const mongoose = require('mongoose');

const utilsModels = require('strapi-utils').models;
const utils = require('./utils');
const relations = require('./relations');

module.exports = ({ models, target, plugin = false }, ctx) => {
  const { instance } = ctx;

  // Parse every authenticated model.
  Object.keys(models).map(model => {
    const definition = models[model];
    definition.orm = 'mongoose';
    definition.associations = [];
    definition.globalName = _.upperFirst(_.camelCase(definition.globalId));
    definition.loadedModel = {};
    // Set the default values to model settings.
    _.defaults(definition, {
      primaryKey: '_id',
github strapi / strapi / packages / strapi-connector-bookshelf / lib / mount-models.js View on Github external
'use strict';
const _ = require('lodash');
const { singular } = require('pluralize');
const dateFns = require('date-fns');

const utilsModels = require('strapi-utils').models;
const relations = require('./relations');
const buildDatabaseSchema = require('./buildDatabaseSchema');
const {
  createGroupJoinTables,
  createGroupModels,
} = require('./generate-group-relations');

const PIVOT_PREFIX = '_pivot_';

const getDatabaseName = connection => {
  const dbName = _.get(connection.settings, 'database');
  const dbSchema = _.get(connection.settings, 'schema', 'public');
  switch (_.get(connection.settings, 'client')) {
    case 'sqlite3':
      return 'main';
    case 'pg':
github strapi / strapi / packages / strapi-hook-bookshelf / lib / index.js View on Github external
'use strict';

const path = require('path');

const _ = require('lodash');
const bookshelf = require('bookshelf');
const pluralize = require('pluralize');

const utilsModels = require('strapi-utils').models;

const utils = require('./utils/');
const relations = require('./relations');

const PIVOT_PREFIX = '_pivot_';
const GLOBALS = {};

/**
 * Bookshelf hook
 */
module.exports = function(strapi) {
  const hook = _.merge({
    /**
     * Default options
     */
    defaults: {