Tag: 水线

从sailsjs模型中的集合中检索特定的值

Merchant.js module.exports = { attributes: { name:{ type:'string', required:true }, drinks:{ collection:'Drinks', via:'merchant' } } }; Drinks.js module.exports = { attributes: { name:{ type:'string', required:true }, category:{ model:'Category' }, merchant:{ model:'Merchant' } } }; Category.js module.exports = { attributes: { name:{ type:'string', required:true, unique: true } } }; 我想要检索与给定的input类别相关的饮料的商家。 有人可以帮助我查找查询。 谢谢

创build并添加到集合,如果不存在sails.js

我对sails.js和node.js 都很陌生 ,所以这可能不是一个Sails的具体问题,但是我创build了一个User和Tag模型,这样User就有很多标签,反之亦然。 用户模型的相关属性是: # models/User.js tags : { collection: 'Tag', via: 'users' }, add_tag: function( name ) { var self = this; Tag.findOne({ name: name }) .then( function( found ){ if( found ) { sails.log.info('found tag ' + found) found.users.add( self.id ); self.save( sails.log.info ); } else { sails.log.info('didnt find tag, creating with ' […]

从关系中select特定的字段

我正在用waterline(使用mysql适配器)在node.js(sails)上构build一个webapp。 我已经设法让关系像这样工作: //Post.js attributes post_statistics: { collection: 'postStatistics', via: 'post' } 我可以很容易地find与该行的关系logging: var query = {user:userId}; // Just filtering by the user query.is_public = Post.POSTS_ONLY_ACTIVE; // Only showing active posts, boolean query.select = ['id','title','content']; // id is only needed for me to get the join working Post.find(query).populate('post_statistics').exec(cb); 一切工作正常,但我只需要从post_statisticsselect特定的字段。 这似乎没有做任何事情,但是,我希望它的工作: Post.find(query).populate('post_statistics',{select:['post','user','id']}).exec(cb); 将字段名称添加到初始select更糟,因为这些字段已经定位到发布表。 任何理智的方法,使这项工作,或者我将不得不写整个查询?

如何在sails的相关字段上查找查询

有没有可能在sails中查询关联的字段属性。 例如,我们来考虑这两个模型: 产品 : attributes: { name:{ type:'string' }, code:{ type:'string', required:true, unique:true }, inventory:{ collection:'inventory', via:'product' } } 库存 attributes: { product:{ model:'product', required:true }, quantity:{ type:'float' } } 现在有什么方法可以获得具有特定codes Products的Inventorylogging。 一种方法是获得这些特定codes products ,然后获得具有这些products Inventorylogging。 但有可能做一个查询查询来获得所需的结果吗? 我试过以下,但是这不会过滤code products 。 Inventory .find() .populate('product',{where:{code:{'contains':'something'}}}) .exec(function (err, inventories) { //do something })

帆:如何使用吃水线连接两个不同的模型

在MVC人们正在使用连接查询来join两个不同的表,但在sails.js我必须使用? 水线有什么方法?

一帆风顺的js填充条件不工作?

我是Sails的新手,我遇到了一对一的问题。 首先,我有模型用户: module.exports = { schema: true, identity : "User", tableName: "user", attributes: { email: { type: 'email', unique: true, required: true }, password: { type: 'string' }, salt: { type: 'string' }, merchant: { model: 'merchant', defaultsTo: null }, removed: { type: 'boolean', required: true, defaultsTo: false } } } 而我的商家模式: module.exports = { […]

SailsJS错误:找不到模块'sails / node_modules / waterline / lib / waterline / query / deferred'

每当我启动SailsJS我得到这个错误: Error: Cannot find module 'sails/node_modules/waterline/lib/waterline/query/deferred' testing不能运行,因为每当它尝试提升帆testing,它会得到一个错误,并停在那里。 请帮忙。

waterline-model.create – primaryKey

我有以下模型与主键ID: attributes: { id: { type: 'integer', autoIncrement: true, primaryKey: true, unique: true }, name: { type: 'string', unique: true, required: true }, } 我正在创build模型如下: var model = { id: undefined, name: 'name', }; waterlinemodel.create(model).exec(function(error,result){}); 但它会抛出错误: Error(E_UNKNOWN)遇到一个意外的错误]详细信息:错误:列“id”中的空值违反非空约束 由于“id”是主键,水线不应该看“id”属性的值。 如何解决这个错误? 我不想删除'id',因为我已经为模型创build了value对象,并且它包含了model的所有属性。我正在根据需要设置value对象的属性。 我不需要为创build设置id属性。

使用吃水线时应指定哪种types的图像?

Sails中的水线非常酷,这个抽象层是非常有用的。 我的问题是:如何使用水线存储图像? 有一个称为二进制的types。 我应该使用那种types吗? 我应该像其他数据types一样处理图像吗? 如何validation一个图像,说确保其格式是几个给定的选项,如PNG,JPEG等

某些时候航行js会话并不会破坏

我已经使用sails js创build了一个web应用程序。 以下是注销function。 logout: function(req, res) { req.session.destroy(function(err) { res.redirect('/'); }); } 有时用户不能从一次点击中注销。 但无论如何,用户正在redirect到我的主页。 然后我必须再次点击注销button才能注销用户。