Where can I define Sequelize associations?
Hello, I've just started with using this full-stack to create my new project. I've set up PostgreSQL as my main database, but here comes the problem: I am a little bit confused with model associations...where should I put them? Here is for example my product.model.js file ... is it possible to add a rule belongsTo(Something) here or not?
export default function(sequelize, DataTypes) {
return sequelize.define('Product', {
timestamps: true,
_id: {
type: DataTypes.INTEGER,
allowNull: false,
primaryKey: true,
autoIncrement: true
},
buyUrl: DataTypes.STRING,
createdAt: 'dateAdded',
updatedAt: false,
ean: {
type: DataTypes.STRING,
unique: true,
validate: {
isNumeric: true,
},
}
}
Ah, I found it :-D
Hi @ketysek , How have you done ?
@ketysek where did you put it?
it can be put in file server\sqldb\index.js (I am using postgress)
Thanks @ketysek . I've putted in there too. Just a quick question: where do you put a model that not necessarily have an api ( like a through table )?
I think updating server\sqldb\index.js with a helpful comment to let those know where to define relationships. It would be easy and effective :)
help me, where did you put it?