Skip to content

Instantly share code, notes, and snippets.

@greyscaled
Created May 24, 2018 14:39
Show Gist options
  • Save greyscaled/3b34caee8a220e9a683510cc6a2eb2eb to your computer and use it in GitHub Desktop.
Save greyscaled/3b34caee8a220e9a683510cc6a2eb2eb to your computer and use it in GitHub Desktop.
const db = require('../models')
db.sequelize.sync().then(function () {
// Require our JSON
const cardJson = require('../.data/cards.json').cards
// For Each card, let's associate it!
cardJson.forEach(async card => {
// get the Model for the current card
const cardModel = await db.Card.findOne({
where: {
name: card['name']
}
})
// associate each element
card.elems.forEach(async el => {
const elemModel = await db.Element.findOne({
where: {
elem: el.toLowerCase()
}
})
await cardModel.addElement(elemModel) // magic!
})
// associate each class
card.classes.forEach(async cl => {
const classModel = await db.Class.findOne({
where: {
class: cl.toLowerCase()
}
})
await cardModel.addClass(classModel)
})
const KingdomModel = await db.Kingdom.findOne({
where: {
name: card['kingdom'].toLowerCase()
}
})
await cardModel.setKingdom(KingdomModel)
})
})
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment