Tag: 水线

水线(nodejs)中的自定义模型属性

我正在寻找小费。 我有一个水线模型,必须由控制器“扫描”,以根据每个属性的属性执行操作。 我来给你展示 attributes: { bar: { model: "Baz", MyCustomModule: {// should be ignored by Anchor's validation foo: false } }, bar: { type: "string", unique: true, MyCustomModule: {// should be ignored by Anchor's validation foo: true } } } 属性MyCustomModule会触发一个错误,而不是在我的应用程序的启动,但在第一个对该模型的请求。 /some/path/node_modules/sails/node_module/anchor/lib/match/matchRule.js:37 throw new Error('Unknown rule: ' + ruleName); ^ Error: Unknown rule: MyCustomModule at […]

Sailsjs蓝图中查找查询的修饰符

阅读Sailsjs Docs for Blueprints find where ,我碰到以下的一段: 您可以select提供带有Waterline WHERE条件对象(其编码为JSONstring)的where参数,而不是基于特定属性进行过滤。 这使您可以利用contains,startsWith和其他子属性条件修饰符来实现更强大的find()查询。 例如?where = {“name”:{“contains”:“theodore”}} 我在哪里可以find其他的子属性条件修饰符 ?

使用Sails.js水线在多个模型中进行高效的查询

我正试图find一种有效的方法来检索分布在多个模型上的结果。 在我的例子中,我有三种模式: 存储video数据的Video ,包括video的创build者 存储用户数据的用户 存储哪个用户跟随哪个其他用户的跟随Follower 我的模型的简化版本如下所示: // Video.js module.exports = { attributes: { title: { type: 'string' }, creator: { model: 'User' } } }; // User.js module.exports = { attributes: { user_name: { type: 'string' } } }; // Follower.js module.exports = { attributes: { user: { model: 'User' }, follower: { model: […]

Sailsjs Model.update不能在控制器中工作

只是一个快速的初学者问题… 控制器是否允许在Sails中执行更新? 我知道行动路线,但是我不能得到这样的代码来更新。 //controller code (this DOES NOT update) Packets.update({packet:5},{cron:'locationhistory'}) .then( function(r){ console.log(r); }); 这个过程起作用,所以我很困惑,为什么上面不会。 //controller code that does work, however I'm calling a custom function sails.models.packets.updateMyPacket('locationhistory', 9, function( response ){ console.log(response); }); // model code updateMyPacket: function( p, num, cb) { Packets.update({ cron: p}, {packet: num}).then( function( packets){ cb(packets); }); } 任何人都可以帮忙吗? 我错过了什么? 谢谢Matt

如何在水线中更新一个查询

在SQL中,我可以使用内联计算来更新字段, UPDATE user SET count=count+1 WHERE id=userID 它只需要一个数据库操作。 但是,在waterline中,我现在唯一的select是查询用户,更改值并保存回数据库。 User.findOne(userID).exec(function(err, user) { if(user) { user.count++; user.save(function(err) { if(!err) console.log("success"); }); } }); 它需要双重数据库访问。 我怎样才能减less开销?

航行蓝图生命周期

我需要添加一些额外的数据,以find蓝图的结果。 我发现这个解决scheme: module.exports = { find: function(req, res) { return sails.hooks.blueprints.middleware.find(req, res); } } 但是我不能在这里find任何改变回应的方法,或者将callbackjoin到蓝图中。 我甚至试图改变蓝图,并在其中添加cb: module.exports = function findRecords (req, res, cb) { … if (typeof cb === 'function') res.ok(cb(result)); else res.ok(result); 但在这种情况下,它每次返回500个状态码(但是有相应的数据)

types对象的sailsjs模型属性,可能吗?

以下是我的帆模型,每当我尝试保存()我得到以下错误 [Error: Unknown rule: address] 使用与mongoose类似的模型,没有任何问题,有人可以看到我的模型中的任何错误? 谢谢! /** * Users.js * * @description :: TODO: You might write a short summary of how this model works and what it represents here. * @docs :: http://sailsjs.org/documentation/concepts/models-and-orm/models */ module.exports = { connection: 'MongoServer', attributes: { AcctSessionId: {type: 'string', required: false, default: ''}, UserName: {type: 'string', required: true, […]

水线将现有数据库迁移到水线模型,无风帆

Error (E_UNKNOWN) :: Encountered an unexpected error : Trying to define a collection (external_resource) which already exists. 我正在尝试为现有的数据库创build一个模型。 我不使用风帆。 只是水线独立。我有连接设置迁移安全。 但是,waterline仍在尝试创build一个已存在于我的预先存在的数据库中的表。 如果我让tableName成为一个新的名字,它可以正常工作。 这个问题似乎是当我尝试使用现有表中的现有数据,然后创build一个水线模型。 我相信这是一个错误,因为迁移安全永远不应该试图创build一个表呢? 我正在使用没有风帆的水线。 水线configuration如下: “` models = []; fs.readdirSync(HOMEDIR + '/lib/models/waterline').forEach(function(file) { models.push(require(HOMEDIR + '/lib/models/waterline/' + file)); }); module.exports = { init: function(next) { models.forEach(function(model) { orm.loadCollection(model); }); orm.initialize(config, function(err, models) { if […]

使用嵌套或条件的多个where(或AND)?

如何在mongodb中使用水线ORM在Sailjs中进行查询,使用多个AND条件,每个条件都具有嵌套OR条件。 一个示例MySQL查询将是: SELECT * FROM Users WHERE (score IS NULL OR activity IS NULL) AND (invited IS NULL OR invited_by IS NULL) 使用多个.where()似乎不工作,也使用OR prop中的所有条件销毁逻辑。 任何解决scheme?

根据列表中的值查询模型

当我通过电子邮件查询用户时: User.findOne({email: 'a@a.com'}).done(function(err, u){console.log(u.sessionTokens);}) 我有它的代币清单: [ { token: '8dfe6aa0-2637-4b3f-9a3c-3ae8dc225b77', issuedAt: Tue Jan 14 2014 14:40:22 GMT+0100 (CET) } ] 但是,当我在这个列表中查询一个令牌时,它不检索用户: User.findOne({'sessionTokens.token':'8dfe6aa0-2637-4b3f-9a3c3ae8dc225b77'}).done(function(err, u){console.log(u);}) => undefined 有任何想法吗 ? User.findOne({'sessionTokens.token':'8d…77'})是否是正确的查询? 编辑 我的用户模型是这样的: module.exports = { schema: true, attributes: { email: { type: 'email', required: true }, encryptedPassword: { type: 'string' }, sessionTokens: { type: 'array' }, … } […]