How to use the loopback-datasource-juggler.DataSource.super_ function in loopback-datasource-juggler

To help you get started, we’ve selected a few loopback-datasource-juggler 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 EdgeVerve / oe-cloud / server / boot / 03_db-models.js View on Github external
var model = app.models[key];
    model.clientModelName = key;
    model.clientPlural = model.pluralModelName;
    util.attachOverrideModelFunction(model);
    model.disableRemoteMethod('createChangeStream', true);
    app.locals.modelNames[key.toLowerCase()] = model.modelName;
    app.locals.modelNames[key] = model.modelName;
    if (key !== model.modelName) {
      return callback();
    }
    var modelDefinitionObject = util.getFileBasedModelSettings(model);
    // add the 'name' member
    modelDefinitionObject.name = key;

    // to avoid crash due to max event listener check
    DataSource.super_.defaultMaxListeners = DataSource.super_.defaultMaxListeners + 1;
    modelDefinition.findOne({ 'where': { 'name': key } }, util.bootContext(), function modelDefinitionFindOneFn(err, modelDef) {
      if (err) {
        log.error(util.bootContext(), 'modelDefinition.findOne name="', key, '" Error: ', err);
        return callback(err);
      }
      if (!modelDef) {
        modelDefinition.create(modelDefinitionObject, util.bootContext(), function modelDefinitionCreateFn(err, res) {
          if (err) {
            log.error(util.bootContext(), 'modelDefinition.create obj=', modelDefinitionObject, ' Error: ', err);
            return callback(err);
          }
          callback();
        });
      } else {
        callback();
      }