diff --git a/README.md b/README.md index d0d235f..08234a4 100644 --- a/README.md +++ b/README.md @@ -274,7 +274,7 @@ OR ] ``` -# Build options, save optons +#### Build options, save optons For each model you can provide build options that are passed to Model.build() and save options that are passed to instance.save(), example: @@ -296,6 +296,30 @@ For each model you can provide build options that are passed to Model.build() an ``` +#### 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 diff --git a/lib/loader.js b/lib/loader.js index b4bf346..db0cfa6 100644 --- a/lib/loader.js +++ b/lib/loader.js @@ -53,9 +53,7 @@ Loader.prototype.loadFixture = function(fixture, models, cb) { var where = {}; Object.keys(Model.rawAttributes).forEach(function(k) { - if (data.hasOwnProperty(k) && - ((!fixture.keys || !fixture.keys.length) || - (fixture.keys && fixture.keys.length && fixture.keys.indexOf(k) > -1))) { + if (data.hasOwnProperty(k) && (!fixture.keys || fixture.keys.indexOf(k) !== -1)) { where[k] = data[k]; } }); diff --git a/package.json b/package.json index 718e425..c40ef8f 100644 --- a/package.json +++ b/package.json @@ -1,6 +1,6 @@ { "name": "sequelize-fixtures", - "version": "0.4.0", + "version": "0.4.1", "description": "sequelize fixture loader", "main": "index.js", "scripts": {