Created
October 3, 2013 13:14
-
-
Save milosdakic/6809627 to your computer and use it in GitHub Desktop.
sequelize associations issue
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
module.exports = function(State, Country) { | |
var data = require('../db/au.json'); | |
// Create states | |
State.bulkCreate(data).done(function() { | |
// Find all newly added states where country associations is not set. | |
State.findAll({ where: { countryId: null }}).done(function(states) { | |
// Find the country we want to associate this with | |
Country.find({ where: { name: 'Australia' }}).success(function(australia) { | |
// Set country association | |
// Australia.hasStates(data).success(function(truthy) { | |
australia.setStates(states); | |
// }); | |
}); | |
}); | |
}); | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment