domasx2/sequelize-fixtures — pull request #2 by dennisschaaf (2013-10-28 15:25:46+00:00)
Title: Allow an external caller to do some transforms to the data

Allow an external caller to do some transformations to the data before it is saved, by passing a 'transformFixtureDataFn' function to the options object.

For Example we needed to generate time stamps relative to the time at which the import is run, so that the imported data has differnt time stamps. Eg:
sequelize_fixtures.loadFile('server/fixtures/*.json', models, {
transformFixtureDataFn: function (data) {
// Fixtures with negative numbers allow creating data objects
// relative to the time of the import.
if(data.createdAt
&& data.createdAt < 0) {
data.createdAt = new Date((new Date()).getTime() + parseFloat(data.createdAt) * 1000 * 60);
}
return data;
}
});