Skip to content

Instantly share code, notes, and snippets.

@joaop221
Last active June 14, 2021 23:07
Show Gist options
  • Save joaop221/05cd1903c9349d4651a07e30512d3320 to your computer and use it in GitHub Desktop.
Save joaop221/05cd1903c9349d4651a07e30512d3320 to your computer and use it in GitHub Desktop.
Compartilhando caixinha de areia com a Carol s2
// 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);
Copy link

ghost commented Jun 2, 2021

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment