Tag: 模型

Ember模型和SQL – 在服务器上或通过Ember关系连接表?

有了Ember,你可以find一些关于构build博客和做清单的教程,但是似乎没有太多需要更复杂模型的东西。 我正在寻找更多的指导,以确定在Ember中是否有处理复杂规范化数据的最佳实践。 例如,我正在开发一个酒窖应用程序,我正在使用8个不同的表格来模拟瓶装葡萄酒(虽然细节并不重要): wines categories bottle_varietals wine_varietals producers appellations regions countries 为了展示葡萄酒瓶,我需要join所有这些数据。 我看到了两种方式: 在服务器端进行join,然后将一揽子葡萄酒瓶发送给您只有wine_bottle模型的客户端。 创build与每个表对应的8个Ember模型,并使用hasMany , belongsTo等创buildEmber关系 这两种方式似乎都是可行的,就像他们有优点和缺点一样。 鉴于Ember是一个“自以为是”的框架,在这个框架中是否有一个“Ember Way”,还是这只是开发者的口味?

在expressjs中创build模型

我有一个快速的应用程序,从外部API获取其数据 api.com/companies (GET, POST) api.com/companies/id (GET, PUT) 我想创build一个模型,使代码更容易维护,你可以看到我在这里重复了很多代码。 router.get('/companies', function(req, res, next) { http.get({ host: 'http://api.com', path: '/companies' }, function(response) { var body = ''; response.on('data', function(d) { body += d; }); }); res.render('companies', {data: body}); }); router.get('/companies/:id', function(req, res, next) { http.get({ host: 'http://api.com', path: '/companies/' + req.params.id }, function(response) { var body = […]

打破单独的文件夹中的后续模型

我真正的问题是:是否有可能与单独的文件夹中的模型sequelize工作? 我这样问,因为我试图在我的应用程序中使用模块化结构,为了实现我需要的模型,控制器和path在同一个文件夹中,这就是我的意思: ├── node_modules ├── src │ ├── client │ │ └── … //Frontend things managed by angular (like views, etc…) │ └── server | ├── components | | ├── db | | | ├── migrations | | | | ├── users.js | | | | └── … | | | ├── seeders | | […]

Sails.js相同模型多对多协会

Sails.js .10 rc8 我完全没有想到这个 我有一个名为User的模型,我想将它集合到其他用户(如朋友列表)中。 像一个多对多的关联 //User.js friends: { collection: 'user', via: 'friends' } 但是当我运行.populate('friends')它不填充任何东西。 有任何想法吗?

sailsjs beforeCreate没有被触发

我有一个非常基本的模型的空船0.9.8应用程序: module.exports = { attributes: { nickname: 'string', encryptedPassword: 'string', beforeCreate: function(values, next){ values.encryptedPassword = "123"; next(); } } }; 当我从控制台创build一个新的用户时,beforeCreate方法不被调用,因此没有创buildencryptedPassword。 我敢肯定,我在这里错过了一些东西,但无法find什么。 任何想法 ?

Sails.js中的模型validation失败

我在Sails.js中testing了以下Employee.js模型,并发现了一些难以理解的东西。 在创build新员工的表单发布时,Employee.js模型的第一个定义中出现以下错误,但Employee.js的第二个定义正常工作。 那么Employee.js的两个定义有什么区别呢? 错误: Error (E_VALIDATION) :: 3 attributes are invalid at WLValidationError.WLError (/usr/local/lib/node_modules/sails/node_modules/waterline/lib/waterline/error/WLError.js:33:18) at new WLValidationError (/usr/local/lib/node_modules/sails/node_modules/waterline/lib/waterline/error/WLValidationError.js:20:28) at /usr/local/lib/node_modules/sails/node_modules/waterline/lib/waterline/query/validate.js:45:43 at allValidationsChecked (/usr/local/lib/node_modules/sails/node_modules/waterline/lib/waterline/core/validations.js:195:5) at done (/usr/local/lib/node_modules/sails/node_modules/waterline/node_modules/async/lib/async.js:135:19) at /usr/local/lib/node_modules/sails/node_modules/waterline/node_modules/async/lib/async.js:32:16 at /usr/local/lib/node_modules/sails/node_modules/waterline/lib/waterline/core/validations.js:186:14 at done (/usr/local/lib/node_modules/sails/node_modules/waterline/node_modules/async/lib/async.js:135:19) at /usr/local/lib/node_modules/sails/node_modules/waterline/node_modules/async/lib/async.js:32:16 at /usr/local/lib/node_modules/sails/node_modules/waterline/lib/waterline/core/validations.js:157:64 Invalid attributes sent to Employee: • name • `undefined` should be a string (instead of "null", which is […]

使用node-mysql编写MySQL Node.js模型

我试图find一些使用node-mysql编写MySQL模型的好习惯。 以下是我到目前为止: var client = app.settings.client; // Client is set in Express settings var table = 'users'; var User = function() { } // Create the user with data from Facebook User.prototype.createFromFacebook = function (name, first_name, last_name, email, location, gender, facebookId, facebookToken, callback) { client.query( 'INSERT INTO ' + table + ' SET name = […]

如何用sails.js定义模型的实例方法

我如何定义Sails中的对象的函数/实例方法? 在Waterline doc( https://github.com/balderdashy/waterline )中他们说: var User = Waterline.Collection.extend({ … attributes: { … // You can also define instance methods here fullName: function() { return this.firstName + ' ' + this.lastName } }, } 但是当我尝试在Sails中的模型的属性中定义一个实例方法时,该函数不会被添加到对象中。 难道我做错了什么 ? 环境:Sails(v0.8.94),Node(v0.8.16)

如何在同一模型的模式方法中创build模型实例?

学科。 我想在它init中创build一个新的模型实例静态方法: var Schema = new mongoose.Schema({…}); //… Schema.statics.createInstance = function (name, pass) { var newPerson = new Person; // <— or 'this', or 'Schema'? newPerson.name = name; newPerson.pass = pass; newPerson.save(); return newPerson; } // … module.exports = db.model("Person", Schema); 我怎么能做到这一点?

如何创build一个正常的风帆模型,而不在模型文件夹

所以, 我正在为我的应用程序实现一个插件API,插件可以有自己的模型,想象一下。 SimplePlugin = { pluginName: 'simple', pluginConfig: {}, SimpleModel: { attributes: { name: 'string' } } } 所以我需要能够创build一个“一次性”的模型,只要有需要的function,它需要具有完全相同的function,因此您自动得到的URL像/simplePlugin/:id为find /simplePlugin/:id 谢谢