sails.js

How to define instance methods for models with sails.js

隐身守侯 提交于 2019-12-04 00:18:40
问题 How can I define functions/instance method for objects in Sails ? In Waterline doc (https://github.com/balderdashy/waterline) they say: var User = Waterline.Collection.extend({ ... attributes: { ... // You can also define instance methods here fullName: function() { return this.firstName + ' ' + this.lastName } }, } But when I try do define an instance method in attributes in a model in Sails, the function is not added to the object. Am I doing something wrong ? Environment: Sails (v0.8.94),

sailsjs, using through relation, how to get the value of non related models?

心不动则不痛 提交于 2019-12-03 22:22:55
I have 3 models named as "User, Pet and UserPet". User model "user_name" : { type: "string", required: true }, "pets" : { collection: 'pet', via: 'user', through: 'userpet' } Pet model "pet_name" : { type: "string", required: true } UserPet Model user: { model: 'user' }, pet: { model: 'pet' }, user_expected_price: { type: "float", required: true } Query used to retrieve the data User.find().populateAll().exec(function (err, data) { console.log(data); }) I can get all the data from above mentioned models except user_expected_price in userpet model because this field is not related with any

Sailsjs - How to use mySQL

混江龙づ霸主 提交于 2019-12-03 21:16:59
How to use mysql with Sails ? Also, if I change the database to a mySQL one, do I lose all my current model data ? I spent some time looking for tutorials and demos but haven't found any. In order to use mySQL with sails, you will have to: Define an adapter in config/adapters Example adapters file: module.exports.adapters = { 'default': 'disk', disk: { module: 'sails-disk' }, 'mysql-adapter': { module: 'sails-mysql', host: 'HOST', user: 'USER', password: 'PASSWORD', database: 'DATABASE' } }; Make any model use the new mysql adapter (ex. api/models/Contact.js) module.exports = { tableName:

How can I include javascript assets selectively in SailsJS?

老子叫甜甜 提交于 2019-12-03 20:43:43
In a Sails.js application, how can I include javascript assets selectively? For instance, if I have an admin page and admin.js lives inside the assets/js directory. How do I keep the admin.js from loading on the public index page? I'm aware that I could move the js out to the public directory, and include the script in my admin view's template. But I'm still unable to include it after the assets.js() call inserts it's javascript. I need it to be inserted after the sails.io.js script is loaded. Is there any way to selectively load scripts and still have access to the sails.io.js which is

I am confused with Sails.js waterline one-to-one association logic

断了今生、忘了曾经 提交于 2019-12-03 20:27:00
问题 So the reason why im confused, because I am a PHP developer and used Laravel and FuelPHP alot What i dont really understand is the association it self. What i mean, i wanted to create a basic hasOne / BelongsTo logic, with the following User has one profile Profile belongs to an user I am used to the following build up (Laravel style) Users table id | username | email | password --------------------------------------- 1 | My Username | My email | 1234568 Users_profile table user_id | first

Mocha tests, clean disk database before every file runs

耗尽温柔 提交于 2019-12-03 18:14:35
问题 I am using Sails 1.x. Is it possible to reset the Sails.js database before each test file runs? I want it to be in state after sails.lift() completes before each run. I followed the docs here - https://sailsjs.com/documentation/concepts/testing - but did not end up with any solution like this. The only solution I'm having right now is to change the lifecyle.test.js before and after to run beforeEvery and afterEvery - https://sailsjs.com/documentation/concepts/testing - so this is lifting

How to access external api using sails.js?

安稳与你 提交于 2019-12-03 17:03:22
I am trying to access information from facebook within a controller using sails.js. Here is my code: module.exports = { commonLikes : function(req,res){ var other_uid = req.param('uid'); //var me = req.params.user.uid; console.log(other_uid); User.findOne({uid : other_uid}).done( function(err,data){ var other = data; var http = require('http'), options = { host : "https://graph.facebook.com", port : 80, path : "/"+other.uid+"/likes?access_token="+other.token, method : 'GET' }; var webservice_data = ""; var webservice_request = http.request(options, function(webservice_response) { webservice

$sce:itype Attempted to trust a non-string value in a content requiring a string: Context: resourceUrl

人盡茶涼 提交于 2019-12-03 15:59:43
I want to play songs stored in my sails server. Path is http://localhost:4000/images/123.mp3 . In front end, i'm using ng-repeat to list that songs from server. <div ng-repeat="tones in ringTones track by $index"> <div> <i ng-show="playpause" class="fa fa-play-circle" ng-click="playpause=!playpause" onclick="plays(event);"><audio id="audio_{{$index}}" ng-src="tones.tonePath"></audio></i> <i ng-show="!playpause" class="fa fa-pause" ng-click="playpause=!playpause" onclick="stop(event);"></i></div> </div> This audio source cause external resource problem <audio ng-src="tones.tonePath"></audio> in

How do I namespace my api in sails.js like so /api/v1?

守給你的承諾、 提交于 2019-12-03 14:31:00
I want to namespace my api requests to /api/v1/ Maybe later some also to api/v2/. How can I do this efficiently in sails.js? Benedikt There is three ways of doing this. 1st: blueprints http://sailsjs.org/#!/documentation/reference/sails.config/sails.config.blueprints.html how to create a global route prefix in sails? prefix: '/api' or restPrefix: '/api' how to create a global route prefix in sails? 2nd: in each controller adding _config: { prefix: '/api/v2' } 3rd: configure it in the routes http://sailsjs.org/#!/documentation/concepts/Routes '/api/v2/': 'FooController', Whereas other

Push values into array of mongodb database through (sails js) waterline

廉价感情. 提交于 2019-12-03 13:39:42
node js,sails js,waterline. I need to update(or push) values into the below schema after insert I am using sailsjs with waterline and mongodb. { "countries": { "states": [ { "statename": "state", "districts": [ { "distname": "district", "cities": [ { "cityname": "Hyderabad", "places": [ { "placename": "hitechcity" } ] } ] } ] } ] } } I need to know how to update it i need something like this after update { "countries": { "states": [ { "statename": "state", "districts": [ { "distname": "district", "cities": [ { "cityname": "Hyderabad", "places": [ { "placename": "hitechcity" }, { "placename":