waterline

sails/waterline where association not exist

此生再无相见时 提交于 2020-01-07 03:04:00
问题 I'm using sails for my latest project, and would like to query a model for items that do not have an association. For example title collection... [ { id : 1, name : "ABC123", media : 1 }, { id : 2, name : "DEF456" } ] media collection... [ { id : 1, name : "1234.mpg", title : 1 }, { id : 2, name : "5678.mpg" } ] So, you can see that title 1 is associated (one to one) with media 1, and visa-versa, and that title 2, and media 2 are not associated with anything. My question is, using the

Get total count in Sails JS blueprint API

风流意气都作罢 提交于 2020-01-06 03:23:13
问题 Can I use pagination or limit + skip that has a return "total page" or "total count" in sails js? 回答1: I guess you mean when you use sails blueprint api methods? Unfortunately in current sails version (v0.11.3) you can't. You must send another request for counting. That blueprint method also don't exist in current sails version, but you can use "sails-hook-blueprint-count" package which enable count method with filtering on all defined models. "sails-hook-blueprint-count" package is available

How does the SANE stack represent parent/child relationships on a single model

别等时光非礼了梦想. 提交于 2020-01-05 11:37:54
问题 How do I represent a parent/child relationship on the same model? An example of this is a model representing a folder. A parent folder can have many children folders. But a child folder can only have one parent folder. Ember.js has the concept of reflexive relations. I would like to implement the first option. "... explicitly define the other side, and set the explicit inverse accordingly ..." How would I go about setting that up on the sails.js side of the SANE stack? 回答1: I'm not sure what

Sails min, max, minLength, maxLength for number and string types gives userError

可紊 提交于 2020-01-05 09:28:00
问题 I am using waterline v0.13.5 package with expressjs. I get an user error { userError: The attribute 'str' on the 'action' model contains invalid properties. The property 'minLength' isn't a recognized property. when trying to use min, max (with number type) and minLength, maxLength (with string type). This same type of error is also received with isIn property when used like this "isIn": [1,2,3] . autoPK: true also doesnt work as expected. It forces me to define _id in the model attributes

Dynamically define and get Models in Waterline

て烟熏妆下的殇ゞ 提交于 2020-01-03 01:58:11
问题 I was wondering if it's possible in Waterline to define models or get a model by name like in Node-ORM2. Defining: var Person = db.define("person", { name : String, surname : String, age : Number, // FLOAT male : Boolean, continent : [ "Europe", "America", "Asia", "Africa", "Australia", "Antartica" ], // ENUM type photo : Buffer, // BLOB/BINARY data : Object // JSON encoded }, { methods: { fullName: function () { return this.name + ' ' + this.surname; } }, validations: { age: orm.enforce

How to Log in SailsJS

十年热恋 提交于 2020-01-01 04:08:08
问题 What is the actual syntax to log in SailsJS? Docs don't have anything, but found the following line in the site's roadmap "Pull out Sails.log (winston wrapper) as a separate module so it can be used by waterline" I image it's something like: Sails.log(...) Sails.error(...) Sails.warn(...) 回答1: In your controllers, models, services, and anywhere else that the sails global is available, you can log with one of: sails.log(); sails.log.warn(); sails.log.info(); sails.log.debug(); sails.log.error(

Sails.js/Waterline populate deep nested association

被刻印的时光 ゝ 提交于 2019-12-30 17:22:28
问题 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

SailsJS - How to specify string attribute length without getting error when creating record?

♀尐吖头ヾ 提交于 2019-12-30 06:52:07
问题 I'm using Sails 0.9.8 paired with MySQL and wanting to do something like this localhost:1337/player/view/<username of player> instead of localhost:1337/player/view/<id of player> So I put something like this in the model: 'username' : { type: 'string', unique: true, minLength: 4, maxLength: 32, required: true }, But I've got an error whenever I run sails lift: { [Error: ER_TOO_LONG_KEY: Specified key was too long; max key length is 767 bytes] code: 'ER_TOO_LONG_KEY', index: 0 } So after I run

SailsJS - How to specify string attribute length without getting error when creating record?

浪尽此生 提交于 2019-12-30 06:51:25
问题 I'm using Sails 0.9.8 paired with MySQL and wanting to do something like this localhost:1337/player/view/<username of player> instead of localhost:1337/player/view/<id of player> So I put something like this in the model: 'username' : { type: 'string', unique: true, minLength: 4, maxLength: 32, required: true }, But I've got an error whenever I run sails lift: { [Error: ER_TOO_LONG_KEY: Specified key was too long; max key length is 767 bytes] code: 'ER_TOO_LONG_KEY', index: 0 } So after I run

How do I handle a Unique Field in sails?

爱⌒轻易说出口 提交于 2019-12-30 01:35:10
问题 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(...)