FAQ Database Discussion Community


Sails.js : Waterline OR filter not working

node.js,sails.js,where-clause,waterline
I am developing a sails.js app using default waterline. I have an array of categories and locations as shown below. var categoryOrFilter = [1,2,3]; var locationsOrFilter = [8,9,10]; I am trying to write a where on my model which will filter the model items belonging to at least one of...

How to update (override) a collection association's value in sails.js?

sails.js,waterline
I have a model that has an attribute that is a collection association: Take for example, a User model below. module.exports = { attributes: { pets: { collection: 'pet' } } } I am aware that I can add pets to a user instance with user.pets.add(3); But how could I...

One model attribute equal to the other by default in sail.js model

javascript,node.js,model-view-controller,sails.js,waterline
Is there a way to set one attribute equal to the other in sails.js model before it is not updated? Something like: username: { type: 'string', required: true }, fullname: { type: 'string', defaultsTo: this.username }, ... ...

Selecting specific fields from a relationship

node.js,waterline
I'm building a webapp on node.js (sails) with waterline (using mysql adapter). I've managed to get relationships working like this: //Post.js attributes post_statistics: { collection: 'postStatistics', via: 'post' } I can easily find the relationship records with the line: var query = {user:userId}; // Just filtering by the user query.is_public...

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

ember.js,orm,sails.js,relationship,waterline
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...

Sails.js app fails to deploy on heroku

node.js,heroku,sails.js,waterline
My sails.js application works fine on localhost but fails on heroku. I have below settings in my production.js port: process.env.PORT || 1337, environment: process.env.NODE_ENV || 'development', Still getting below messages and deployment fails; 2015-02-10T03:54:55.089482+00:00 app[web.1]: Tue, 10 Feb 2015 03:54:55 GMT i18n:debug read /app/config/locales/de.json for locale: de 2015-02-10T03:54:55.089220+00:00 app[web.1]: Tue,...

ER_BAD_FIELD_ERROR in sails.js using waterline

javascript,sails.js,waterline
I know there are similar questions but they haven't help me. I've got an error when trying to use .find() method on model: product2 (.query() method is working ) I was trying to find out how to get more verbose output from database, but with failure. { "error": "E_UNKNOWN", "status":...

Waterline-OrientDB - Bi-Directional Edge

node.js,sails.js,orient-db,waterline,sails-orientdb
I have two models declared in Sails and I'm using the Waterline-Orientdb adapter and don't know how to connect them via a bi-directional edge Questions Model var Waterline = require('waterline'); module.exports = Waterline.Collection.extend({ tableName: 'questionsTable', identity: 'questions', connection: 'associations', attributes: { id: { type: 'string', primaryKey: true, columnName: '@rid'}, question...

How to extend waterline with custom query methods?

javascript,node.js,orm,sails.js,waterline
I want to create and use some custom query methods for waterline. For example method makeItAwesome: Article.makeItAwesome({ id: 42 }).exec(function(err, awesomeArticle) { /* ... */ }); Of course I can add this makeItAwesome to model's static methods but what if I want common stuff reusable for other models. Does sails.js...

Sails model query

node.js,mongodb,model,sails.js,waterline
I have 3 models (Room, Module and Device) : Room : /** * Room.js * * @description :: TODO: You might write a short summary of how this model works and what it represents here. * @docs :: http://sailsjs.org/#!documentation/models */ module.exports = { attributes : { name : { type...

How do custom and multilanguage messages errors on sails js

javascript,node.js,sails.js,waterline
I saw this question, he explain the method for create a custom messages but not says how do messages with multi languages in the errors. Thanks for your help.

Model with multiple Edges using Sails.js and OrientDB

node.js,sails.js,graph-databases,orient-db,waterline
I am new to Sails.js and OrientDB. I am trying to figure out how to create a model that has multiple edges using the sails-orientDB adapter. I have a vehicle model that stores basic vehicle information and a vehicle color: module.exports = { schema: true, tableName: 'Vehicle', attributes: { id:...

How can i get the full related model in view in sails.js?

orm,sails.js,one-to-many,waterline,sails-mongo
I've created a sails.js application. I'm trying to get full related model Creator in view but I get only id... How can I do this? I'm doing this: Model Author.js module.exports = { attributes: { name: { type: 'string', required: true }, description: { type: 'string' }, history: { type:...

Dynamic Table Specification Per Model Object

node.js,mongodb,sails.js,waterline
I am trying to figure out a way to create dynamic model types, stored in their own respective collections (for a CMS). I want to be able to define a new "content type" and have it stored in it's own collection, and use a standard Sails model to control each...

Update sails model without trigger lifecycle?

sails.js,waterline
I know that model.save({ silent: true }, callback); is not supported. But anyone know how to update Sails model without trigger lifecycle event?? I have ask on github issue, but still no respond so far. Link is here...

Check for existing user doesn't go along

mongodb,sails.js,waterline
As the Waterline's unique attribute is ignored for MongoDB, I take up the decision to make a check for existing model entry in my code: var username = req.param('username'); var email = req.param('email'); var asd = ""; // Do check if user already exists User.findOne({username: username}, function (err, user) {...

Sails.js controller not inserting into Mongo database

mongodb,sails.js,waterline
I've been all over SO and Sailsjs.org trying to figure out what's going wrong, and to no avail. Just trying to learn the basics of SailsJS. I have a UserController, whose create() method gets called when a POST request is sent to /user. create: function (req, res) { var params...

Bidirectional Many to many association on Sails.js

javascript,orm,many-to-many,sails.js,waterline
I'm starting to use Sails.js (I'm an absolute newbie), and I want to create the following class model. I have a Student and a SubscriptionList. The Student has a Collection of subscriptionLists to which he/she is subscribed, and the SubscriptionList knows all the Students that are subscribed to it. So,...

Server-side Pagination in Sails with DataTables

jquery,pagination,datatables,sails.js,waterline
I am currently using the server-side option of DataTables, my current problem is that the page numbers in the data table only displays 1. To further explain here is my code: Javascript: var oTable1 = $('#users-table').dataTable({ "bDestroy": true, "bProcessing": true, "bServerSide": true, "sAjaxSource": "/v1/users", "bPaginate": true, "aoColumns": [ { "mData":...

SailsJS Waterline with Bluebird Promises

node.js,sails.js,waterline
When using the waterline ORM, if I want to consume the bluebird promise api thats shipped by default how to I pass the processing back to the controller. Below is the code : module.exports = { //Authenticate auth: function (req, res) { user = req.allParams(); //Authenticate User.authenticate(user, function (response) {...

When call beforeUpdate method in Sails models?

sails.js,waterline
I go by sailscast I create in User model module.exports = { attributes: { login: { type: 'string', }, password: { type: 'string', }, birthDate: { type: 'date', } }, beforeCreate: function(values, next) { //someCode(); }, beforeUpdate: function(values, next) { console.log("i\'m here!"); if (values.birthDate && _.isNaN(Date.parse(values.birthDate))) { console.log(values.birdDate); return next({err:...

Unable to retrieve records from database

sails.js,waterline
I'm trying to retrieve a record with this: var users = User.find({ username: "andy" }).then(function(users){ return users; }); console.log(users); return res.send(users); But I get returned: { "isFulfilled": false, "isRejected": false } ...

sailsjs: how do I reverse engineer an existing db into sails/waterline models?

sails.js,waterline,sails-postgresql
I am a SailsJS noob. I have an existing database (postgres) that I want to turn into models for SailsJS/Waterline. is there a method/tool/utility to do this automatically like the datasource.discoverSchema() method in LoopBack? thanks, Mark...

Waterline orientdb database connections timing out

node.js,sails.js,orient-db,waterline,sails-orientdb
With SailsJS/Waterline I am using the waterline-orientdb adapter to connect to and commit my domain objects to OrientDB. Everything with that is fairly straightforward except for the frequent connection timeouts that I'm getting from the database. orientdb: { adapter: 'waterline-orientdb', host: 'somehost', port: 2424, user: 'someuser', password: 'somepassword', database: 'somedatabasename'...

SailsJS is unstable on Amazon elastic beanstalk

amazon-web-services,sails.js,elastic-beanstalk,waterline
I'm using sails.js on an elastic beanstalk auto-scaling deployment, but things are misbehaving, it seems very unstable. For example, (seemingly) out of the blue the following custom model method, that had been running fine for the last 3 months or so, stopped working var obj = this.toObject(); obj.permissions = obj.getPermissions();...

Foreign key constraint on SailsJS

database,node.js,relational-database,sails.js,waterline
This is my College model module.exports = { attributes: { name:{ type:'string', required:true }, location:{ type:'string', required:true }, faculties:{ collection:'faculty', via:'college' } } }; This is my Faculty model module.exports = { attributes: { name:{ type:'string', required:true }, description:{ type:'string' }, college:{ model:'college', required:true } , years:{ collection:'year', via:'faculty' }...

Best way to migrate table changes to production sailsjs tables

node.js,sails.js,waterline
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...

Add new Document into field type Json through Waterline

node.js,sails.js,waterline,sails-orientdb
I am trying to add a new document or you can say a new key value pair to an existing json type field, but it is replacing the older key value pair e.g. before my embedded field was {"@type":"d","key1":"example1"} and when I executed the update call WL_MODELS.numbers.update({id: req.body.SID},{numbers: {"key2":"example2"}},function(err,model){ if(err)...

ObjectID not storing hexadecimal value

javascript,node.js,mongodb,sails.js,waterline
Originally, my Sails/Mongo was storing the ObjectID in the database as follows: "_id" : ObjectId("557077fb836bdee256004232") Not sure what changed or happened, but now new records are being stored as follows: "_id" : { "_bsontype" : "ObjectID", "id" : "UtÓ-Åß\u0010C&5", "generationTime" : 1434552692 } This is only occurring in 2 developer...

How to increase values with sails-mysql?

sails.js,waterline
I want UPDATE `some_table` SET `count` = `count` + 1 WHERE `id` = 1 I find a way like this SomeModel.find(1).done(function (model){ model.count += 1; model.save() }) How to do this with Model.update()?...

SailsJS: beforeUpdate (Lifecycle callback), access current values

javascript,node.js,sails.js,waterline
It's clear how to access the new values, the first argument contains them beforeUpdate: function (values, cb) {....} But how can I access the current values, that are to be replaced?...

Set migrate:safe to user defined table in waterline

waterline,node-mysql
I have to create user defined tables in waterline though custom query method(.query()). custom.con.query("CREATE TABLE "+req.body.table_name+",function(err,model){}); After that i have to create coloumns in this table again through custom query. custom.con.query("ALTER TABLE "+req.body.table_name+" ADD "+req.body.coloumn_name,function(err,model){}); Problem is once table is created and it's coloumns also created.but when i restart server...

Sails/Waterline Populate doesn't work as expected

mysql,node.js,sails.js,waterline
I'm bangin' my head against the wall in the last hours, and I can't figure out a solution to my problem. In my sails models, I have 2 one-to-many associations. 'A' model can have many 'B', and 'B' model can have many 'C'. In my controller, when I do a.find().populate('b')...

Sails.js Model: create 2 association to self failed

node.js,sails.js,waterline,sails-mongo
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...

Odd “timeouts” when attempting to execute a MongoDB query from a Sails.js app

node.js,mongodb,express,sails.js,waterline
When I start my Sails application in a localhost environment and load it in a browser, the view will render fine, an async request to another (non-mongo) resource works fine, but any async requests back to Sails that fetch data from Mongo works only within the first few moments of...

binary field, Waterline ORM

mysql,node.js,file,sails.js,waterline
I'm trying to insert a file represented by a node JS buffer object in a table field (MySQL) (type binary in waterline js), When reading it and writing it into a file, the file is corrupted, i implemented a java program that updates the line in the table containing the...

How can I filter populated values in sails.js?

javascript,node.js,join,sails.js,waterline
I have model User. To simplify my issue it has not attributes (except id that is produced by sails engine): module.exports = { } I have also model UserPost: module.exports = { attributes: { user: { required: true, model: 'user' } } } I want to find posts of user...

Get Count of related records in sailsjs

sails.js,waterline
I have an artist model that has a collection of songs. I am not populating the related songs in the blueprints config, but I would like to at least get a count back so I know how many songs are on each artist. Here is what my simple artist model...

cannot retain id of first table in left join

mysql,node.js,sails.js,waterline
I am using sails waterline ORM and i have three tables in my model layer 1-s_class attributes: { c_title:{ type:'string', required: true }, sec:{ collection:'s_section', via:"cls" }, s_session:{ model:'s_session', columnName:'session' } } 2-s_section attributes: { sec_title:{ type:'string' }, sec_priority:{ type:'integer', required: true }, cls:{ collection:'s_class', via:"sec" } } 3-s_form attributes:...

Is there some way to overwrite default formatting and validation for specific type?

node.js,sails.js,waterline,sails-postgresql
I have a model User with a "birthday" field of type "date". The problem is that waterline converts its value to the JavaScript Date object that is restricted to minimum of the year 1970. Obviously there are some people with a year of birth less than 1970. So is there...

Sails hook passport

express,sails.js,passport.js,waterline,sails-hook
I'm trying to implement Passport strategies into a sails hook, like this I can share on multiple project. When I try to log I have this error : Error: passport.initialize() middleware not in use at IncomingMessage.req.login.req.logIn (/Users/jaumard/IdeaProjects/HookPassportTest/node_modules/sails-hook-passport/node_modules/passport-github/node_modules/passport-oauth/node_modules/passport/lib/passport/http/request.js:30:30) at...

Sails service returns MongoDb results when no Waterline associations exist but then fails when they DO exist

node.js,mongodb,sails.js,waterline,sails-mongo
I'm building a sails.js api with MongoDb as my db. Those are my models (simplified just for the sake of this question): models/Passport.js simplified: identifier: { type: 'string' }, owner: { model: 'User', required: true }, models/User.js simplified: username: { type: 'string', unique: true }, passports: { collection: 'Passport', via:...

Dynamically define and get Models in Waterline

javascript,node.js,orm,sails.js,waterline
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" ],...

Private fields with sql query

node.js,sails.js,waterline
I recently changed my queries on the SQL database from Model.findOne().populate("Model2").exec(function(err, result) { }) to : Model.query(sqlQuery, parameters, function(err, result) { }) The reason I changed the queries are performances problems : it goes much faster using the second way than the first one (when you join tables). My question...

sails.js: Lifecycle callbacks for Models: Do they support beforeFind and afterFind?

sails.js,models,waterline
In sails.js, Models support lifecycle callbacks for validate, create, update and destroy. Is there support for callbacks for find() or query as well? Like beforeFind() and afterFind()? The idea is same. I would want to validate / modify parameters before the query is run or after the query is run....