gadelkareem / sails-dynamodb

Amazon DynamoDB adapter for Waterline / Sails.js
http://sailsjs.org
46 stars 22 forks source link

Error creating Object #48

Closed ggarcia92 closed 6 years ago

ggarcia92 commented 6 years ago

Hi,

I am using this module and when I tried to create an Object Sails send me back ("Type mismatch for attribute to update")

This is my code: Model:

module.exports = {
  attributes: {
    id:{
      type: 'string',
      primaryKey: 'range'
    },
    picture:{
      type: "string",
      required: true
    },
    title:{
      type: "string",
      required: true
    },
    subcategories:{
      collection: 'Subcategory',
      via: 'category_ref'
    },
    user_ref:{
      model: 'User'
    }
  }
};

Controller:

create: function (req, res, next) {
           let  name = "sometext";
            var obj = {
                id: new String(uuidv4()),
                picture: name,
                title: req.param('title')
            }
            Category.create(obj, function (err, cat) {
                if (err) {
                    return next(err);
                } else {
                    return res.send(cat);
                }
            });
        });
    },

I verified with an instanceof and it is an String.

My Sails version is 0.12.14.

Thanks in advance

ggarcia92 commented 6 years ago

I solved the problem casting req.param(title) to string like this String(req.param(title)). Also I needed to delete old local database after model changes.