sails.js - SailsJS best practice to seed database with data before other Models are initialized -


there model other models assume existence. should initialized before api function called.

the way (it doesn't work):

1) define model in api/models, let's call location.js

2) add following bootstrap.js

    var locations = require('../api/models/locations.js');      module.exports.bootstrap = function (cb) {        // seed database locations         var locationsobj = {             country: 'australia',             states: ['brisbane', 'perth', 'sydney']         };         location.create(locationsobj, function locationsobj(err, locations) {             if (err) {                 cb(err);             }             console.log('locations created: ', locations);         });   } 

question 1 right way initial database seeding?

i error:

locations.create(locationsobj, function locationsobj(err, locations) {           ^ typeerror: object #<bject> has no method 'create' 

question 2 how cb function of bootstrap work? if there error, do?

the sails models globally available; don't need require @ bootstrap.js.

this use seed database. (see links enclose go gists)

  1. include seed function @ config/models.js. methods declare in file extended models. link: seed method gist

  2. define de data seed consume in model link: model's seed data

  3. call seed method in config/bootstrap.js using async. link: calling method

update

have @ threat also: best way migrate table changes production sailsjs tables


Comments

Popular posts from this blog

apache - Remove .php and add trailing slash in url using htaccess not loading css -

javascript - jQuery show full size image on click -