mirror of
https://github.com/knex/knex.git
synced 2025-12-25 22:18:43 +00:00
fixing #38 shouldn't mutate insert array
This commit is contained in:
parent
e290513713
commit
a14ebd23f7
2
knex.js
2
knex.js
@ -785,7 +785,7 @@
|
||||
// Sets the values for an `insert` query.
|
||||
insert: function(values, returning) {
|
||||
if (returning) this.returning(returning);
|
||||
this.values = this._prepValues(values);
|
||||
this.values = this._prepValues(_.clone(values));
|
||||
return this._setType('insert');
|
||||
},
|
||||
|
||||
|
||||
@ -1,5 +1,6 @@
|
||||
|
||||
var uuid = require('node-uuid');
|
||||
var deepEqual = require('assert').deepEqual;
|
||||
|
||||
module.exports = function(Knex, dbName, resolver) {
|
||||
|
||||
@ -156,6 +157,21 @@ module.exports = function(Knex, dbName, resolver) {
|
||||
|
||||
});
|
||||
|
||||
it('should not mutate the array passed in', function(ok) {
|
||||
|
||||
var a = {enum_value: 'a', uuid: uuid.v4()};
|
||||
var b = {enum_value: 'c', uuid: uuid.v4()};
|
||||
var x = [a, b];
|
||||
|
||||
Knex('datatype_test')
|
||||
.insert(x)
|
||||
.then(function() {
|
||||
deepEqual(x, [a, b]);
|
||||
ok();
|
||||
})
|
||||
.then(null, ok);
|
||||
});
|
||||
|
||||
});
|
||||
|
||||
};
|
||||
Loading…
x
Reference in New Issue
Block a user