Created
May 24, 2018 14:39
-
-
Save greyscaled/3b34caee8a220e9a683510cc6a2eb2eb to your computer and use it in GitHub Desktop.
This file contains 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
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