waterline

Sails.js/Waterline populate deep nested association

自闭症网瘾萝莉.ら 提交于 2019-12-01 15:28:25
I understand that there is no built-in way in Sails.js/Waterline of populating deep nested associations yet, so I am trying to use bluebird promises to accomplish that but I'm running into a problem. I'm successfully retrieving the user, and all the posts (populated with the images collection) associated with it (console.log shows me that everything is filled properly). However, when I override the property "post" of the user and try to assign the fully populated posts retrieved before, it does not fill properly the images property of Post.js. It is like the ORM is preventing the image

How to use Model.query() with promises in SailsJS/Waterline?

你。 提交于 2019-12-01 15:24:11
I'm having issues with Sails.JS 0.9.8. I would like to use promises with the Model.query() function (I use sails-mysql adapter). This code will work : User.findOne({ email: email }) .then(function(user) { console.log(user); }); but this one won't User.query("SELECT email FROM user WHERE email = ?", [ email ])) .then(function(err, rows) { console.log(rows); }) I get undefined for both 'err' and 'rows'. Is it just not implemented or I am doing something wrong ? If not implemented, is there any alternative to use promises with .query() ? Thank you in advance You can promisify(User.query) yourself

Unique property fails in Sails.js

﹥>﹥吖頭↗ 提交于 2019-12-01 15:19:28
The following code represents an Account Model in Sails.js v0.9.4 . module.exports = { attributes: { email: { type: 'email', unique: true, required: true }, password:{ type: 'string', minLength: 6, maxLength: 15, required:true } } }; When I send two POSTS and a PUT request via Postman to localhost:8080/account, the unique property of the email fails. Specifically, I send the following HTTP requests from Postman: POST http://localhost:8080/account?email=foo@gmail.com&password=123456 POST http://localhost:8080/account?email=bar@gmail.com&password=123456 PUT http://localhost:8080/account?id=1

How to use Model.query() with promises in SailsJS/Waterline?

烈酒焚心 提交于 2019-12-01 14:24:37
问题 I'm having issues with Sails.JS 0.9.8. I would like to use promises with the Model.query() function (I use sails-mysql adapter). This code will work : User.findOne({ email: email }) .then(function(user) { console.log(user); }); but this one won't User.query("SELECT email FROM user WHERE email = ?", [ email ])) .then(function(err, rows) { console.log(rows); }) I get undefined for both 'err' and 'rows'. Is it just not implemented or I am doing something wrong ? If not implemented, is there any

Is there a bettery way to work with nested(associated) models in Sails JS?

守給你的承諾、 提交于 2019-12-01 14:07:27
I've connected my SailsJs app to a Mongodb database. I'm working on an analytic application. These are the major models in my application: User Project Report Event A user can have many projects, a project can have many reports and a report can have many events. I have created these relations using collection and model properties of my models attributes. My problem is why is it so hard to find events of specific user? I wish I could do this: User. find({id: id}). populate('projects'). populate('reports'). populate('events'). then(function (eventsOfMyUser) { }); but since only projects is an

How to get added record (not just the id) through publishAdd()-notification?

大兔子大兔子 提交于 2019-12-01 08:35:41
问题 Each Sails.js model has the method publishAdd(). This notifies every listener, when a new record was added to a associated model. This notification does not contain the newly created record. So I have to start another request from the client side to get the new record. Is there a possibility, that Sails.js sends the new record with the notification, so I can reduce my request count? Solution I realized the accepted answer like that: https://gist.github.com/openscript/7016c5fd8c5053b5e3a3 回答1:

Using mix of AND and OR clause in sails and waterline

一笑奈何 提交于 2019-12-01 07:59:39
问题 How can I use OR and AND clause in Sailsjs and its ORM Waterline? For example I have a table of books _______________________________________ | book_name | author | free | public | _______________________________________ | Book-A | Author-1 | false | true | --------------------------------------- | Book-B | Author-1 | true | true | --------------------------------------- | Book-C | Author-1 | false | false | --------------------------------------- | Book-D | Author-2 | true | true | ---------

Sort by the association with populate

…衆ロ難τιáo~ 提交于 2019-12-01 07:34:10
I have Articles and Comments linked by a one-to-many association (an Article can have many Comments). I would like to obtain the most commented articles so I proceed like that : function mostCommentedArticles () { var deferred = Q.defer(); Article.find().populate('comments').sort('comments ASC').exec(deferred.makeNodeResolver()); return deferred.promise; } BUT, I don't obtain the expected result : it doesn't sort at all (by Comments or anything else) Is there an other way to proceed or is it an issue? Thanks, Pierre Melvin You pass it in the second parameter of .populate() like this: .populate

Sort by the association with populate

随声附和 提交于 2019-12-01 05:53:00
问题 I have Articles and Comments linked by a one-to-many association (an Article can have many Comments). I would like to obtain the most commented articles so I proceed like that : function mostCommentedArticles () { var deferred = Q.defer(); Article.find().populate('comments').sort('comments ASC').exec(deferred.makeNodeResolver()); return deferred.promise; } BUT, I don't obtain the expected result : it doesn't sort at all (by Comments or anything else) Is there an other way to proceed or is it

sails.js + waterline One-To-Many model association, what should happen when deleting the Many?

放肆的年华 提交于 2019-12-01 04:28:33
I have a one to many relation between Teacher(One) and Children(Many). If I do: Teacher.destroy(teacherId).exec(function(err){}); The children are not automatically removed. Is it a bug or should I delete them manually? If that's not a bug, what is the explanation for not deleting children? Waterline currently doesn't support cascading deletes. It may be a configuration option in future versions, but it will probably never be the default. In most production-ready apps you probably should be doing soft-deletes anyway. In either case, you can get what you want by using the afterDestroy lifecycle