sails.js

How to selectively populate waterline associations via query param in sails.js

喜欢而已 提交于 2019-11-30 06:40:46
By default, sails will populate all relationships within a model when it's corresponding API route is hit. Does anyone know if it's possible to toggle this functionality? If I'm working with a one-to-many association, I may not want to populate the association when doing a listing of all items for performance reasons. But when viewing a single item, it would be nice to complete the population. For example, say one ticket can have many comments. I don't care about the comments when fetching a case listing but would be important when viewing a specific case. I took a guess at how it could

sails.js - how can I acess session data in Model hook beforeCreate

爷,独闯天下 提交于 2019-11-30 05:32:32
问题 I want to update a field 'owner' of a Model. The owner needs to be fetched from the session which contains the user who is currently logged in and is creating the Model. I want something like this: Model = { attributes: { }, beforeCreate(values,next) { var owner_user_id = req.session.user_id; values.owner = owner_user_id; next(); } } 回答1: Are you sure a lifecycle callback is the right place to do it? Because it's really not. What if tomorrow you'll need to use your model in a CLI task or

How do I handle a Unique Field in sails?

僤鯓⒐⒋嵵緔 提交于 2019-11-30 05:22:24
I've defined a unique field in my model but when I tried to test it seems like it's not being checked by sails because I get a Error (E_UNKNOWN) :: Encountered an unexpected error: MongoError: E11000 duplicate key error index: instead a sails ValidationError. What is the best way to handle a unique field in sails? // model/User.js module.exports{ attributes: { email: {required: true, unique: true, type: 'email' }, .... } // in my controller User.create({email: 'hello@gmail.com'}).then(...).fail(....) User.create({email: 'hello@gmail.com'}).then(...).fail(// throws the mongo error ) // and same

Sails.js query on an associated value

为君一笑 提交于 2019-11-30 05:09:42
I'm using Sails.js version 0.10.0-rc4 . All models are using sails-mysql. I'm trying to query a model which has an "one-to-many" association to another model (the query is happening on the "many" side). It looks something like this: Post.find() .where({ category: category_id }) .populate("category") .exec( ... ) This gives me an empty array back however when I leave out the .populate("category") I get the correct result set. I know that I could leave .populate("category") out and then fetch each correlating Category object separately, but I'm wondering if there's a better solution to this

Sails.js Model: create 2 association to self failed

≯℡__Kan透↙ 提交于 2019-11-30 05:01:38
问题 I'm pretty new on Nodejs and sails. I'm implementing a server which is similiar to Twitter. In user model, there should be 2 fields: follower and following, and the 2 fields are association of the model 'user' itself. My question is when the model have only 1 association, either follower or following, it works. However, when both follower and following included, there would be en error. The code is something like this: module.exports = { attributes: { alias: { type:'string', required: true,

Sails.js form post not submitting any data

大兔子大兔子 提交于 2019-11-30 04:49:41
问题 Recently I came to face an unusual problem while posting a form. The form post works fine when there is no attachment or the attachment image file size is less than 100kb. But when I tried to upload a file larger than 100kb no element in the form is being posted/submitted. When I console.log() the value it gives undefined. I can't understand what is causing the problem. No errors are shown on console screen. Can anyone help with this problem? var name = req.param('name'); console.log(name);

Sails.Js - How I do pagination in sails.Js

冷暖自知 提交于 2019-11-30 04:46:22
I want to create paginated table using sails.js, mongodb and waterline-ORM. Is there a any specific way to do pagination in sails.js? http://sailsjs.org/#/documentation/concepts/ORM/Querylanguage.html Model.find().paginate({page: 2, limit: 10}); Model.find({ where: { name: 'foo' }, limit: 10, skip: 10 }); If you want the pagination to work asynchronously, its very easy to do with JQUERY $$.getJSON and on the server res.json(); Theres a lot of info in waterline and sails docs. There is also another way. if you want to fetch data from the front-end, and have turned blueprint on, you can also try

How to perform SQL Joins and Relations in Sails.js and Waterline?

懵懂的女人 提交于 2019-11-30 04:45:40
Can anyone guide me on how to setup relational schema & performs joins in sails.js ? particlebanana Associations are officially Supported in Waterline Overview From the docs : With Sails and Waterline, you can associate models across multiple data stores. This means that even if your users live in PostgreSQL and their photos live in MongoDB, you can interact with the data as if they lived together in the same database. You can also have associations that span different connections (i.e. datastores/databases) using the same adapter. This comes in handy if, for example, your app needs to access

sails-mysql schema datatypes

旧街凉风 提交于 2019-11-30 04:22:36
问题 anyone used node's sails framework using mysql as DB (https://github.com/balderdashy/sails-mysql)? I am stuck in models, I can't create the database structure.The datatypes that I need to use to create the schema doesn't work. I've searched everywhere for some documentation, but i can't find anything that can help me. Sail's documentation is not yet complete, i guess. http://sailsjs.org/#documentation/models Can anyone please help me in creating models. I would highly appreciate if you can

how to create a global route prefix in sails?

旧巷老猫 提交于 2019-11-30 02:58:41
问题 I just recently started using sails and nodejs. I was wondering, is there an easy way to create a global prefix using the configuration available in Sails? Or would I need to bring in another library? I found the blueprint prefix configuration in config/controller.js. It seems there ought to be an easy way to do this since the application already partially supports it... I'm trying to get something like /api/v1 in front of all routes I have for my application. Thanks. 回答1: You can set the