Huge News!Announcing our $40M Series B led by Abstract Ventures.Learn More
Socket
Sign inDemoInstall
Socket

sequelize-fixtures

Package Overview
Dependencies
Maintainers
1
Versions
39
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

sequelize-fixtures - npm Package Compare versions

Comparing version 0.4.3 to 0.4.4

tests/fixtures/custompk.yaml

21

lib/loader.js

@@ -100,9 +100,10 @@ var Promise = require('bluebird');

val = data[key];
if (assoc) {
if (assoc.associationType === 'BelongsTo') {
promises.push(
assoc.target.find(typeof val === 'object' ? {
where: val
} : {where: {id: val}}).then(function(obj) {
result[assoc.identifier] = obj.id;
(typeof val === 'object' ? assoc.target.find({where: val}) : assoc.target.findById(val))
.then(function(obj) {
result[assoc.identifier] = obj[assoc.target.primaryKeyField];
return Promise.resolve();
})

@@ -115,6 +116,6 @@ );

promises.push(
assoc.target.find(typeof v === 'object' ? {
where: v
} : {where: {id: v}}).then(function(obj) {
(typeof v === 'object' ? assoc.target.find({where: v}) : assoc.target.findById(v))
.then(function(obj) {
many2many[assoc.associationAccessor].push(obj);
return Promise.resolve();
})

@@ -131,3 +132,7 @@ );

} else {
result[key] = val;
if (Model.attributes.hasOwnProperty(key)) {
result[key] = val;
} else {
console.warn('attribute "' + key +"' not defined on model '" + Model.name + "'.");
}
}

@@ -134,0 +139,0 @@ });

@@ -39,2 +39,5 @@ var Promise = require('bluebird'),

return glob(globpath).then(function(filenames) {
if (!filenames.length) {
console.warn("No files matching '" + globpath + "' found.");
}
return Promise.each(filenames, function(filename) {

@@ -41,0 +44,0 @@ return self.readFile(filename).then(function(res) {

{
"name": "sequelize-fixtures",
"version": "0.4.3",
"version": "0.4.4",
"description": "sequelize fixture loader",

@@ -5,0 +5,0 @@ "main": "index.js",

@@ -6,4 +6,3 @@ module.exports = [

"propA": "tralivali",
"propB": 2 + 2,
"status": false
"propB": 2 + 2
}

@@ -15,4 +14,3 @@ },

"propA": "treerre",
"propB": 4 / 2,
"status": false
"propB": 4 / 2
}

@@ -24,6 +22,5 @@ },

"propA": (new Date()).toString(),
"propB": 43,
"status": false
"propB": 43
}
}
];

@@ -6,4 +6,3 @@ [

"propA": "tralivali",
"propB": 2,
"status": false
"propB": 2
}

@@ -15,4 +14,3 @@ },

"propA": "treerre",
"propB": 4,
"status": false
"propB": 4
}

@@ -24,6 +22,5 @@ },

"propA": "1234",
"propB": 43,
"status": false
"propB": 43
}
}
]

@@ -6,6 +6,5 @@ [

"propA": "tralivali2",
"propB": 2,
"status": false
"propB": 2
}
}
]

@@ -10,3 +10,3 @@ var Sequelize = require('sequelize'),

exports.all = [];
['Foo', 'Bar', 'Article', 'Person', 'Project', 'Actor', 'Movie'].forEach( function (model) {
['Foo', 'Bar', 'Article', 'Person', 'Project', 'Actor', 'Movie', 'Producer', 'Play'].forEach( function (model) {
var mod = sequelize.import(__dirname + '/' + model);

@@ -23,3 +23,7 @@ module.exports[model] = mod;

m.Actor.belongsToMany(m.Movie, {through: 'actorsmovies'});
m.Producer.belongsTo(m.Movie);
m.Movie.hasMany(m.Producer);
m.Producer.belongsTo(m.Play);
m.Play.hasMany(m.Producer);
m.Movie.belongsToMany(m.Actor, {through: 'actorsmovies'});
})(exports);

@@ -414,2 +414,34 @@ var sf = require('../index'),

});
it('should handle primary keys not named "id" for has many', function() {
return sf.loadFile('tests/fixtures/custompk.yaml', models)
.then(function() {
return models.Movie.find({
where: {
name: 'Pirates of the Baltic Sea'
}
});
}).then(function(movie){
return movie.getProducers();
}).then(function(producers){
producers.length.should.equal(1);
producers[0].name.should.equal('Somethingstein');
});
});
it('should handle primary keys not named "id" for belongs to', function() {
return sf.loadFile('tests/fixtures/custompk.yaml', models)
.then(function() {
return models.Play.find({
where: {
name: 'Book of Jesus'
}
});
}).then(function(movie){
return movie.getProducers();
}).then(function(producers){
producers.length.should.equal(1);
producers[0].name.should.equal('Arnie');
});
});
});
SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap
  • Changelog

Packages

npm

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc