-
Notifications
You must be signed in to change notification settings - Fork 642
Closed
Labels
Description
Hi I am new to objection.js. I want to insert data by transaction.
I started transaction with PrescriptionMetaData Model and related PrescriptionSymptom Model by relationMappings as followings.
Inside PrescriptionMetaData DAO
static get tableName() {
return "prescription_meta_data";
}
static get relationMappings() {
return {
symptoms: {
relation: Model.HasManyRelation,
modelClass: PrescriptionMetaData,
join: {
from: `${PrescriptionMetaData.tableName}.id`,
to: `${PrescriptionSymptom.tableName}.prescriptionId`,
},
},
};
}
static async upsertOneSymptom(
trxObject: PrescriptionMetaData,
symptomData: Partial<PrescriptionSymptom>
) {
// check for the doc already created
const prescriptionSymptomDoc = await PrescriptionSymptom.query().findOne({
symptomId: symptomData.symptomId,
appointmentId: symptomData.appointmentId,
prescriptionId: symptomData.prescriptionId,
});
if (!prescriptionSymptomDoc) {
// insert operation
const newDoc = await trxObject
.$relatedQuery<PrescriptionSymptom>("symptoms")
.insert(symptomData);
return newDoc;
}
// patch operation
const updatedDoc = await trxObject
.$relatedQuery<PrescriptionSymptom>("symptoms")
.patchAndFetchById(prescriptionSymptomDoc.id, symptomData);
return updatedDoc;
}
Eventually can't able to insert/patch with the following error,
PrescriptionMetaData.relationMappings.symptoms: join: either from or to must point to the owner model table and the other one to the related table. It might be that specified table 'prescription_symptoms' is not correct
Could anyone please help me out.
Reactions are currently unavailable