私の本物の質問は次のとおりです。モデルを別々のフォルダに入れて続けることは可能ですか?別々のフォルダでモデルを中断してください
私はアプリケーション内のモジュラー構造で作業しようとしているので、モデル、コントローラー、および同じフォルダー内のルートを持つ必要があることを実現するために、私はこれを求めています。
├── node_modules
├── src
│ ├── client
│ │ └── ... //Frontend things managed by angular (like views, etc...)
│ └── server
| ├── components
| | ├── db
| | | ├── migrations
| | | | ├── users.js
| | | | └── ...
| | | ├── seeders
| | | ├── config.json
| | | ├── options.json
| | | └── index.js
| | ├── env
| | └── ...
│ ├── modules //By module i mean an entity
| | ├── users
| | | ├── users.model.js
| | | ├── users.controller.js
| | | └── index.js //Here i define the routes
| | └── ...
| └── ...
|
├── package.json
└── server.js
どうすればいいですか?モデルを別々のフォルダに分割するにはどうすればいいですか?
多分、私は何を求めているのですか:どのようにモデル/ index.jsスクリプトを設定して、各ディレクトリからモデルを読み込むことができますか?
モデル/ index.js
'use strict';
var fs = require('fs');
var path = require('path');
var Sequelize = require('sequelize');
var basename = path.basename(module.filename);
var env = process.env.NODE_ENV || 'development';
var config = require(__dirname + '/../config.json')[env];
var db = {};
if (config.use_env_variable) {
var sequelize = new Sequelize(process.env[config.use_env_variable]);
} else {
var sequelize = new Sequelize(config.database, config.username, config.password, config);
}
fs
.readdirSync(__dirname)
.filter(function(file) {
return (file.indexOf('.') !== 0) && (file !== basename);
})
.forEach(function(file) {
if (file.slice(-3) !== '.js') return;
var model = sequelize['import'](path.join(__dirname, file));
db[model.name] = model;
});
Object.keys(db).forEach(function(modelName) {
if (db[modelName].associate) {
db[modelName].associate(db);
}
});
db.sequelize = sequelize;
db.Sequelize = Sequelize;
module.exports = db;
私が考えていた何かが、このような構造を有するモジュールディレクトリの各フォルダの下にxxx.model.jsを探すことです。
modules
├── index.js //The above script configured to read the x.model.js in each folder
├── users
| ├── users.model.js
| ├── users.controller.js
| └── ...
├── questions
| ├── questions.model.js
| ├── questions.controller.js
| └── ...
└── ...
注:私はLaravelのバックグラウンドから来ています。私はあなたがdefiを実行した後に、どのように移行とモデルが異なるかを推測していますNE列のあなたが種類を教えモデル、など。、移行と同じ...
私の質問の多くは[the docs](https://github.com/sequelize/cli#options)で解決されましたが、モデルフォルダが破損していません –
問題の解決方法を教えてください。私はドキュメントから多くを得ていない。 –
@JonathanSolorzano、あなたの問題の解決策を見つけましたか? –