Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Model Args #40

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open

Model Args #40

wants to merge 1 commit into from

Conversation

vkiranmaniya
Copy link

Added possibility to pass the model function arguments in the case of the model function accepts an argument. Conder the usecase.

Mongoose model definition in feathers.js and feathers-mongoose

module.exports = function(app) {
  const modelName = 'category';
  const mongooseClient = app.get('mongooseClient');
  const schema = new mongooseClient.Schema({
    name: String,
  }, {
    timestamps: true,
  });
  if (mongooseClient.modelNames().includes(modelName)) {
    mongooseClient.deleteModel(modelName);
  }
  return mongooseClient.model(modelName, schema);
};

The plugin code, which will actually initiate the seeder

const path = require('path');
const seeder = require('mongoose-seed');
const seedable = require('./seeder/seed');
const logger = require('./logger');

module.exports = function(app) {
    seeder.connect(app.get('mongodb'), function() {

        // requires the app argument to load the model
        seeder.loadModels([
          path.join(__dirname, 'models/category.model.js')
        ], app);

        seeder.clearModels(['category'], function() {
          seeder.populateModels(seedable, function() {
            seeder.disconnect();
          });
        });
    });
  }
};

Added possibility to pass the model function arguments in the case of the model function accepts an argument
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

1 participant