I want to collect data using model sequelize mysql.
For the master data, i have Model ReviewFormModel. Here is the code
class ReviewFormModel {
constructor(sequelizeClient, DataTypes) {
this.sequelize = sequelizeClient;
this.dataTypes = DataTypes;
}
getReviewForm() {
const reviewFormModel = this.sequelize.define('reviewFormModel', {
name: this.dataTypes.TEXT,
type: this.dataTypes.TEXT,
min_value: this.dataTypes.TEXT,
max_value: this.dataTypes.TEXT,
}, {
tableName: 'review_form',
underscored: true,
});
return reviewFormModel;
}
}
module.exports = ReviewFormModel;
That model has many ReviewFormDetail. Here is the model.
class ReviewFormDetailModel {
constructor(sequelizeClient, DataTypes) {
this.sequelize = sequelizeClient;
this.dataTypes = DataTypes;
}
getReviewFormDetail() {
const reviewFormDetailModel = this.sequelize.define('reviewFormDetailModel', {
parent_id: this.dataTypes.INTEGER,
label: this.dataTypes.TEXT,
trans_id: this.dataTypes.TEXT,
}, {
tableName: 'review_form_detail',
underscored: true,
});
return reviewFormDetailModel;
}
}
module.exports = ReviewFormDetailModel;
For collect the data i am using code like this. But i get error. Here is the code i used to collect the data.
this.reviewDetailModel.getReviewFormDetail().belongsTo(this.reviewModel.getReviewForm(), {
foreignKey: 'parent_id', as: 'ReviewForm',
});
this.reviewDetailModel.getReviewFormDetail()
.findAll({ include: [{
model: this.reviewModel.getReviewForm(),
as: 'ReviewForm' }] })
.then((results) => {
console.log(results);
})
.then((res) => {
resolve(res);
});
But I get error like this
Unhandled rejection Error: reviewFormModel (ReviewForm) is not associated to reviewFormDetailModel!
via Delfrinando Pranata
No comments:
Post a Comment