Question

So, with sailsJS you can just put any old data into your model and put it into the database even if the item is not defined in the attributes object.

Is there any way to prevent this happening? is seems silly to try and do an if and then throw errors because there would be too many things to stop getting through.

For example I have just ran into the problem where I have a list of users and I'm displaying them through angular ng-repeat on the frontend and when I put the data to save a user it also decides that "$$hashKey": "00I" is going with them too !

So it automatically saved to the database and when I refresh and get the data again, the "$$hashKey": "00I" is coming back, and therefore causing this error

Error: [ngRepeat:dupes] Duplicates in a repeater are not allowed. Use 'track by' expression to specify unique keys. Repeater: (key, user) in admins | filter:userSearch, Duplicate key: object:00I

This is coming from angular.

ps.

as far as i know, the server is using the default sails-disk

Was it helpful?

Solution

The default mode for Sails.js models is schemaless, which is probably not what you need. So, all you have to do is to add schema to your model:

module.exports = {
 schema: true,

 attributes: {
   // Define all your attributes here...
 }
};

After that all the values that are not described in the attributes will be automatically filtered out during the model saving.

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top