You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
The new example does not show any associations; it would be very useful to show associations being performed as well as suggesting how to organize the code for that.
@papb Just trying to learn more about your code: May I ask why you used a modelDefiner function on each of these models? Why not just define the models in their file and import them like the following?
Your example:
constmodelDefiners=[require('./models/user.model'),require('./models/instrument.model'),require('./models/orchestra.model'),// Add more models here...// require('./models/item'),];
My example:
// top of fileconstuser=require('./models/user.model');constinstrument=require('./models/instrument.model');constorchestra=require('./models/orchesta.model');
Inside of a model:
constinstrument=sequelize.define('instrument',{// The following specification of the 'id' attribute could be omitted// since it is the default.id: {allowNull: false,autoIncrement: true,primaryKey: true,type: DataTypes.INTEGER},type: {allowNull: false,type: DataTypes.STRING,},// type: {// allowNull: false,// type: DataTypes.STRING,// validate: {// isIn: [['string', 'wind', 'percussion']]// }// },purchaseDate: {allowNull: false,type: DataTypes.DATE},// We also want it to have a 'orchestraId' field, but we don't have to define it here.// It will be defined automatically when Sequelize applies the associations.module.exports= instrument;});
What's the advantage of the model files being functions that take sequelize as a parameter? Just trying to learn more!
The new example does not show any associations; it would be very useful to show associations being performed as well as suggesting how to organize the code for that.
See #95 (comment)
The text was updated successfully, but these errors were encountered: