2015-05-10 79 views

回答

2

我发现了一个简单的方法来做到这一点!

我刚刚创建了所有钩子模型文件到主应用“api/models”文件夹的符号链接!

我的初始化函数看起来像:

var path = require('path'); 
var fs = require('fs'); 

module.exports = function ToInitialize(sails) { 

    return function initialize(cb) { 

     // the path of the Hook model 
     var modelFile = path.join(__dirname, '../models/Model.js'); 
     // the destination path 
     var modelFileDest = path.join(sails.config.appPath, 'api/models/Model.js'); 

     if (!fs.existsSync(modelFileDest)) { 
      // create a symlink to the api/models folder 
      fs.symlink(modelFile, modelFileDest, 'file', cb); 
     } else { 
      return cb(); 
     } 

    }; 
}; 
+1

好的解决方法,但我认为这是更好地做到像你对你的问题指向该项目。你可以尝试使用它并在初始化方法上调用injectModel(使用正确的目录参数) – jaumard

+1

以下是如何使用它:) https://github.com/leeroybrun/sails-hook-hookloader/issues/1 – jaumard

+1

哇谢谢这个石头!这正是我需要的。 感谢您在git仓库中的例子,它完美地工作。 – Oubord