domasx2 / sequelize-fixtures

Load data from json, yaml or js to sequelize
301 stars 83 forks source link

Fix duplicate detection to work with JSON arrays #123

Closed villasv closed 2 years ago

villasv commented 4 years ago

So the issue isn't as simple as I hoped initially, sorry for the previous broken build. Here's the conundrum previously happening:

So I implemented a small helper that recursively serializes only arrays, making all tests pass.

villasv commented 4 years ago
villasv@PC  ~/projects/sequelize-fixtures   json-handling  npm test

> sequelize-fixtures@1.2.0 test /home/villasv/projects/sequelize-fixtures
> mocha tests

  fixture (with promises)
    ✓ should load fixture without id
    ✓ should load fixture with id
    ✓ should accept buildOptions in fixture
    ✓ should accept saveOptions in fixture
    ✓ should not duplicate fixtures
    ✓ should load multiple fixtures
    ✓ should not duplicate fixtures whose keys already exist
    ✓ should load fixtures from json
    ✓ should return model count and models
    ✓ should load fixtures from js (implied relative)
    ✓ should load fixtures from js (explicit relative)
    ✓ should load fixtures from js (absolute)
    ✓ should load fixtures from multiple files via glob
    ✓ should load fixtures from multiple files
    ✓ should load yaml fixtures
    ✓ should throw errors if files are missing
    ✓ should load assosication with. natural keys
    ✓ should load assosication with. ids
    ✓ should load many2many assocs by nat keys (41ms)
    ✓ should load belongs 2 many assocs by nat keys
    ✓ should load belongs 2 many assocs by ids
    ✓ empty many2many should not break
    ✓ should load many2many assocs by ids
    ✓ should set many2many even if object already exists
    ✓ should handle primary keys not named "id" for has many
    ✓ should handle primary keys not named "id" for belongs to
    ✓ if transaction specified, it should be passed to models
    ✓ if transaction specified, should load many2many assocs by nat keys
    ✓ should load fixtures and then transform their values
    ✓ should load user modified fixtures
    ✓ should add attributes to many2many through table
    ✓ should perform a set operation if one exists
    ✓ should add attributes to many2many through table using ids
    ✓ should exclude VIRTUAL columns from filter condition
    ✓ should handle json including arrays

  35 passing (2s)
villasv commented 4 years ago

I'm going to squash a single commit

villasv commented 4 years ago

Relates to #68 and #120

villasv commented 4 years ago

I'm still not sure this is going to work with PostgreSQL, but unless we somehow add it to the test suite, I guess the only way to fix this definitively is patching Sequelize itself.

villasv commented 2 years ago

Closing as stale, maybe some day this can be picked up.