domasx2 / sequelize-fixtures

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

When to use transformFixtureDataFn vs modifyFixtureDataFn #82

Open bschlenk opened 7 years ago

bschlenk commented 7 years ago

These two methods look like they are called one after the other, regardless of anything else: https://github.com/domasx2/sequelize-fixtures/blob/master/lib/loader.js#L135-L143

Is there supposed to be a difference between them? Looking at the code it seems that I could choose either one and it would do the same thing. Maybe one should be deprecated since they both seem to be doing the exact same thing?

matmar10 commented 5 years ago

I agree with you @bschlenk this seems like duplicated functionality. They are evaluated very close together in the code:

    // Allows an external caller to modify the data
    // before it is evaluated
    if (this.options.modifyFixtureDataFn) {
        data = this.options.modifyFixtureDataFn(data, Model);
    }

    // Allows an external caller to do some transforms to the data
    // before it is saved
    if (this.options.transformFixtureDataFn) {
        result = this.options.transformFixtureDataFn(data, Model);
    }

The modifyFixtureDataFn seems like it should come after setters, associations, and such are applied.

Removing this would probably be a breaking change but we could at least mark one of them for depreciation and start raising a warning when one is used. Thoughts?