M
M
microf2015-01-01 22:04:06
MongoDB
microf, 2015-01-01 22:04:06

How to write only what is needed in the model?

Hello. Happy New Year
I have an Items model created in sail.js

module.exports = {
  attributes: {         
             en: {type: 'string'},
             ru: {type: 'string'}
       }
};

I want to fill it with a controller and a service:
module.exports = {   
    
  addItem: function(req, res) {      
     var params = {
          en : req.en,
          ru : req.ru         
      };      
        Items.addItem(params, function(success) {
            res.json(success);
        });
    }
};

service:
module.exports = {

 addItem: function(params, next) {
    Items.create({value: params}).exec(function(err, item) {
      if(err) throw err;
      next(item);
    });
  }
};

I do it right in the address bar site.com/items?ru=имя&en=nameand everything is in order. Everything is recorded. But if I do site.com/items?name=name(well, or some other), then a separate name field is still written to the database. And I would like to write only in ru and en - without the ability to create some separate fields by the user. How (and where) can it be validated?

Answer the question

In order to leave comments, you need to log in

1 answer(s)
S
Stanislav Romanov, 2015-01-02
@microf

Hello. Thank you and Happy New Year.
Try setting schema : true in the model parameters.

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question