waterline

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 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 - 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

How to use Sequelize in SailsJs

筅森魡賤 提交于 2019-11-29 22:39:46
Waterline is an excellent ORM but I noticed that there are many features that are not present yet on waterline but Sequelize already have. So I have decided to switch to sequelize but still using Sails for the others things. I have search tutorial how to switch to sequelize but nothing. How can I replace Waterline for sequelize in sails Js? I've moved forward with sequelize as well, there are two project that came out really recently, so i would like to announce them. sails-hook-sequelize: It follows the answer by Manuel Darveau, it will fetch all your models, import through sequelize and

Sails.js populate with where

爷,独闯天下 提交于 2019-11-29 15:21:40
I need to select users with dogs (pets with type equal 'dog') var User = Waterline.Collection.extend({ identity: 'user', attributes: { firstName: 'string', lastName: 'string', pets: { collection: 'pet', via: 'owner' } } }); var Pet = Waterline.Collection.extend({ identity: 'pet', attributes: { type: 'string', name: 'string', owner: { model: 'user' } } }); I didn't find any examples, I tried like this User.find().populate('pets', {type: 'dog'}).exec(err, users) ... and this User.find().where({'pets.type': 'dog'}).populate('pets').exec(err, users) ... but that does not work Would be greate if

Best way to migrate table changes to production sailsjs tables

瘦欲@ 提交于 2019-11-29 15:09:11
问题 I just lost 11,000 records from my database just running the command for sailsjs without the --prod part in it, So I thought I should ask whats the best way to change the tables on production server when the Model.js has been changed ? Thanks 回答1: Automated migration should never be done in production. This a common-sense practice that applies to any production system with important data. There are a few solutions available for migrating a sails.js database. sails-db-migrate: db-migrate

Chaining waterline calls with Promises

不打扰是莪最后的温柔 提交于 2019-11-29 12:11:38
问题 I have been hitting my head off a wall on this for the last 3 days. I am using sailsjs & the waterline ORM that comes bundled. I want to run DB calls one after an other. I know I can do this by nesting inside "then" calls but it just looks wrong. I have gone over the Q documentation and tutorials several times but I still don't get how to connect and fire "then" calls from existing Promises sequentially :( I want to: create a user create a action link the user & action update the user update

npm install not installing things at /usr/bin

余生长醉 提交于 2019-11-29 07:46:39
I am trying to install SailsJS with: $ sudo npm install -g sails It works, install everything at /home/brunoluiz/npm/lib/node_modules/sails with the following log: /home/brunoluiz/npm/bin/sails -> /home/brunoluiz/npm/lib/node_modules/sails/bin/sails.js sails@0.9.16 /home/brunoluiz/npm/lib/node_modules/sails ├── connect-flash@0.1.1 ├── pluralize@0.0.5 ├── inflection@1.2.5 ├── grunt-sails-linker@0.9.5 ├── grunt-contrib-clean@0.4.1 ├── node-uuid@1.4.0 ├── async@0.2.9 ├── grunt-contrib-concat@0.3.0 ├── grunt-contrib-copy@0.4.1 ├── grunt-contrib-coffee@0.7.0 ├── ejs-locals@1.0.2 ├── ejs@0.8.4 ├──

Change field name for CreatedAt / UpdateAt Attributes

陌路散爱 提交于 2019-11-29 06:45:21
问题 I am attempting to model an existing MSSQL table in SailsJS. Unsurprisingly the tables in the existing database have a createdAt and updatedAt column similar to what is generated by the SailsJS framework. Is there a way to assign the value of the property generated by the SailsJS framework to an attribute that I have defined? For example: attributes: { ... creationDate:{ columnName:'cre_dt', type:'datetime', defaultsTo: this.createdAt } ... } 回答1: No, but you can turn off the auto-generated