sequelize-fixtures
Advanced tools
Comparing version 0.4.0 to 0.4.1
@@ -56,3 +56,3 @@ var Promise = require('bluebird'); | ||
Object.keys(Model.rawAttributes).forEach(function(k) { | ||
if (data.hasOwnProperty(k)) { | ||
if (data.hasOwnProperty(k) && (!fixture.keys || fixture.keys.indexOf(k) !== -1)) { | ||
where[k] = data[k]; | ||
@@ -59,0 +59,0 @@ } |
{ | ||
"name": "sequelize-fixtures", | ||
"version": "0.4.0", | ||
"version": "0.4.1", | ||
"description": "sequelize fixture loader", | ||
@@ -5,0 +5,0 @@ "main": "index.js", |
@@ -277,3 +277,3 @@ Sequelize fixtures | ||
# Build options, save optons | ||
#### Build options, save optons | ||
@@ -300,4 +300,28 @@ For each model you can provide build options that are passed to Model.build() and save options that are passed to instance.save(), example: | ||
#### Detect duplicates based on select fields | ||
In case you want to detect duplicates based on specific field or fields rather than all fields (for example, don't include entities with the same id, even if other fields don't match), you can speficy these fields with a 'keys' property. | ||
```json | ||
{ | ||
"model": "Person", | ||
"keys": ["email"], | ||
"data": { | ||
"name": "John", | ||
"email": "example@example.com" | ||
} | ||
}, | ||
{ | ||
"model": "Person", | ||
"keys": ["email"], | ||
"data": { | ||
"name": "Patrick", | ||
"email": "example@example.com" | ||
} | ||
} | ||
``` | ||
In this example only John will be loaded | ||
# grunt task | ||
@@ -304,0 +328,0 @@ |
@@ -127,2 +127,23 @@ var sf = require('../index'), | ||
it('should not load duplicate fixtures whose keys already exist', function(done) { | ||
sf.loadFixtures([FOO_FIXTURE, { | ||
model: 'Foo', | ||
keys: ['propA'], | ||
data: { | ||
propA: 'baz', | ||
propB: 2 | ||
} | ||
}], models, function (err){ | ||
should.not.exist(err); | ||
models.Foo.count({ | ||
where: { | ||
propA: 'bar' | ||
} | ||
}).then(function(c){ | ||
c.should.equal(1); | ||
done(); | ||
}); | ||
}); | ||
}); | ||
it('should load fixtures from json', function(done){ | ||
@@ -129,0 +150,0 @@ sf.loadFile('tests/fixtures/fixture1.json', models, function(){ |
@@ -121,2 +121,21 @@ var sf = require('../index'), | ||
it('should not duplicate fixtures whose keys already exist', function() { | ||
return sf.loadFixtures([FOO_FIXTURE, { | ||
model: 'Foo', | ||
keys: ['propA'], | ||
data: { | ||
propA: 'bar', | ||
propB: 2 | ||
} | ||
}], models).then(function() { | ||
return models.Foo.count({ | ||
where: { | ||
propA: 'bar' | ||
} | ||
}); | ||
}).then(function(c){ | ||
c.should.equal(1); | ||
}); | ||
}); | ||
it('should load fixtures from json', function() { | ||
@@ -123,0 +142,0 @@ return sf.loadFile('tests/fixtures/fixture1.json', models) |
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
49645
1138
346