Last active
June 14, 2021 23:07
-
-
Save joaop221/05cd1903c9349d4651a07e30512d3320 to your computer and use it in GitHub Desktop.
Compartilhando caixinha de areia com a Carol s2
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
// exemplo do objeto de request | |
const request = { | |
body: { | |
disciplina: 'foo', | |
assunto: 'bar', | |
tituloTopico: 'baz', | |
descTopico: 'fob', | |
dia: 'segunda' | |
} | |
}; | |
// controller | |
route.post('/bla', function(req, res, next) { | |
const request = req.body; | |
Topico.create({ | |
titulo: request.tituloTopico, | |
descricao: request.descTopico, | |
dia: request.dia | |
}).then(result => { | |
console.log(result); | |
Disciplina.create({ | |
assunto: request.assunto, | |
idTopico: result.id | |
}).then(result2 => console.log(result2)); | |
}); | |
}); | |
// exemplo de um model do sequilize | |
const A = sequelize.define('A', /* ... */); | |
const B = sequelize.define('B', /* ... */); | |
// ex: Relacionamento de 1 pra 1 de A e B; | |
A.hasOne(B); | |
// ex: Relacionamento de 1 pra N de A e B; | |
A.hasMany(B); | |
//real | |
//Definição de tópico aqui | |
//... | |
Topico.hasOne(Disciplina); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
fonte: https://sequelize.org/master/manual/assocs.html