Skip to content

Commit

Permalink
keys property
Browse files Browse the repository at this point in the history
  • Loading branch information
domasx2 committed Apr 9, 2015
1 parent d7d37a2 commit 4dab9ce
Show file tree
Hide file tree
Showing 3 changed files with 27 additions and 5 deletions.
26 changes: 25 additions & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -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:

Expand All @@ -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": "[email protected]"
}
},
{
"model": "Person",
"keys": ["email"],
"data": {
"name": "Patrick",
"email": "[email protected]"
}
}

```
In this example only John will be loaded


# grunt task
Expand Down
4 changes: 1 addition & 3 deletions lib/loader.js
Original file line number Diff line number Diff line change
Expand Up @@ -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];
}
});
Expand Down
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "sequelize-fixtures",
"version": "0.4.0",
"version": "0.4.1",
"description": "sequelize fixture loader",
"main": "index.js",
"scripts": {
Expand Down

0 comments on commit 4dab9ce

Please sign in to comment.