waterline

Waterline, find array in array

我只是一个虾纸丫 提交于 2019-12-13 13:07:52
问题 I have Video model: module.exports = { attributes: { id: 'string', tags: 'array' }, } I want to find all videos with tags for example "Hello" or "World". I could easy get all videos like: Video.find({tags:"Hello"}). I saw examples where searching id: [1,2,3] but not when key(id => tags) is array. 回答1: Use the "in"-Statement in combination with "contains" Video.find({tags: { contains: ["some1","some2"]}}).exec(function(err,res){ console.log(res); }); See: https://github.com/balderdashy

Sails.js - Get async data from an EJS file

南笙酒味 提交于 2019-12-13 04:42:14
问题 Are there a good way to get async data from an EJS file? Sails.js only have async methods to get data from a database. I have a collection of Pages with their associated content Values . In some cases I want to get a specific Value from another Page (e.g.: in a related page module, a navigation module...). And I need to do that server side , to keep the front-end part SEO friendly . The easier way should be to retrieve all the Pages and Values inside the controller, and then expose a function

SailsJS / Waterline - How do I use a 'string' index in models and associations?

爷,独闯天下 提交于 2019-12-13 04:24:19
问题 Newbie question here. According to https://github.com/balderdashy/waterline#indexing you cannot use a 'string' datatype as an index in Waterline due to issues with case insensitivity: There is currently an issue with adding indexes to string fields. Because Waterline performs its queries in a case insensitive manner, we are unable to use the index on a string attribute. There are some workarounds being discussed but nothing is implemented so far. This will be updated in the near future to

Generate (query) string from “where” object in waterline.js

送分小仙女□ 提交于 2019-12-13 02:38:29
问题 Using waterline.js in sails.js (0.10.5): I would like to create a 'where' string out of a where option object. For example, I have: where = { updatedAt:{">":"2015-01-08T10:00:00.000Z","<=":"2015-01-08T20:00:00.000Z"} }; and I would like to have a generated string (similar to): "WHERE updatedAt > '2015-01-08T10:00:00.000Z' AND updatedAt <= '2015-01-08T20:00:00.000Z'" Is this possible? I have the feeling it should be... 回答1: You can do date range queries using the comparison operators. Model

Should one-to-one associations populate both sides?

泄露秘密 提交于 2019-12-13 01:37:11
问题 I have two models (user & agent). I then create a user and an agent. I am expecting to see the association when using the blueprint routes for BOTH /user and /agent. I am only seeing the user model is associated with an agent via the /agent blueprint. The /user blueprint does not have any reference/association to an Agent. The issue presents itself when I am trying to access the Agent via A userId with the following command: User.findOne(req.body.userId).populate('agent').exec(function(err,

Can I specify a lifecycle callback that fires for all waterline models in sails.js

柔情痞子 提交于 2019-12-12 19:41:15
问题 I'm trying to add some auditing capability to my sails.js app. The afterUpdate lifecycle callback will give me the proper place to do what I need, but I'm hoping to avoid modifying every model to reference my new code. Is there a way to specify an afterUpdate callback that will fire on all models? 回答1: Put your required overrides into config/models.js module.exports.models = { attributes: {}, afterUpdate: function (valuesToUpdate, cb) { // add your logic here... console.log('yep, updated');

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

╄→гoц情女王★ 提交于 2019-12-12 15:56:48
问题 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. Any thoughts? 回答1: As of writing this it does NOT support these requests, however their is a pull request https://github.com/balderdashy/waterline/pull/525 You can use policies to do this in the

Soft delete in Sails/Waterline

纵然是瞬间 提交于 2019-12-12 11:16:48
问题 Trying to delete a user model using: //Hard Delete User.destroy({id:userId}, function(err, res){ //Hard Delete }) I need to do a soft delete on User model and currently setting a flag isDeleted to true on delete and updating document: updateUser.isDeleted = true; User.update({id:userId}, updateUser, function(err, res){ Update project }) and while fetching documents I am doing a check If isDeleted - true or not. Is there any In-built feature provided by Sails or Waterline which I can configure

How to extract distinct values from a mongo database using Waterline and Sails.js (version 0.10)?

╄→гoц情女王★ 提交于 2019-12-12 09:58:42
问题 Using Sails.js version 0.10.x , assume I have a model Dog , populated as follows (writtenout in yaml format for convenience, but in my case it's actually in a mongo database.) dogs: - breed: "wolf" name: "Fido" - breed: "wolf" name: "Roger" - breed: "dingo" name: "Nipper" - breed: "dingo" name: "Ernie" - breed: "corgi" name: "Bernadi" - breed: "corgi" name: "Queenie" - breed: "poodle" name: "Christopher" - breed: "poodle" name: "Tony" etc So now I want to create a list of the available breeds

Restricting fields from being set in Sails.js Model

时光毁灭记忆、已成空白 提交于 2019-12-12 09:19:43
问题 So I have a model with some fields like so: // ... slug: { type: 'string', required: true, alphanumeric: true, minLength: 3, maxLength: 16 }, loggedinAt: 'date', // ... I'm using the Sails blueprint structure so it automatically maps everything. However, sometimes I have fields like loggedinAt which are strictly internal and I don't want them to be able to be set by the user. As it stands if I make a post requests with the loggedinAt field it will set it. How can I restrict this? 回答1: You can