diff --git a/lib/Model.js b/lib/Model.js index 69a0158d0..b69f2042e 100644 --- a/lib/Model.js +++ b/lib/Model.js @@ -47,7 +47,8 @@ async function processCondition (req, options, model) { const val = options.conditionValues[k]; const attr = model.$__.schema.attributes[k]; if (attr) { - req.ExpressionAttributeValues[`:${k}`] = await attr.toDynamo(val, undefined, model, {'updateTimestamps': false}); + const noSet = options.condition.startsWith('contains'); + req.ExpressionAttributeValues[`:${k}`] = await attr.toDynamo(val, noSet, model, {'updateTimestamps': false}); } else { throw new errors.ModelError(`Invalid condition value: ${k}. The name must either be in the schema or a full DynamoDB object must be specified.`); } diff --git a/test/Model.js b/test/Model.js index 03729c5bd..4c73ee907 100644 --- a/test/Model.js +++ b/test/Model.js @@ -2425,6 +2425,39 @@ describe('Model', function () { done(); }); }); + + it('Allows simple string for array attribute in contains condition', (done) => { + const kitten = new Cats.Cat( + { + 'id': 1, + 'name': 'Fluffy', + 'legs': ['front right', 'front left', 'back right', 'back left'] + } + ); + + kitten.save(() => { + const updateOptions = { + 'condition': 'contains(legs, :legs)', + 'conditionValues': {'legs': 'front right'} + }; + + Cats.Cat.update({'id': 1}, {'name': 'Puffy'}, updateOptions, (err, data) => { + should.not.exist(err); + should.exist(data); + data.id.should.eql(1); + data.name.should.equal('Puffy'); + Cats.Cat.get(1, (errA, puffy) => { + should.not.exist(errA); + should.exist(puffy); + puffy.id.should.eql(1); + puffy.name.should.eql('Puffy'); + done(); + }); + }); + }); + + }); + }); describe('Model.populate', () => {