HasManyThrough question: Not able to create multiple links between the same models

14 views
Skip to first unread message

Francois Laforge

unread,
Aug 16, 2017, 9:16:33 AM8/16/17
to LoopbackJS
Using the physician - Patient example in the documentation, I have a question about the hasManyThrough relation

According to the doc, once the relation is created, new methods are added to the models, such that:

physician.patients.add(patient, function(err, patient) {
...
});

After doing some testing I found that you can also add appointment data when adding a patient to the physician as follows:

var appointmentData = {appointmentDate: new Date(2017,1,1)};
physician.patients.add(patient, appointmentData, function(err, patient) {
   ...
});


Question / Observation:

Using the above add() method, I am only able to add a single appointment between the patient and the physician.  When I attempt to add a second appointment to the relation, it is not saved to the database

var appointmentData2 = {appointmentDate2: new Date(2017,2,2)};
// Not saved
physician.patients.add(patient, appointmentData2, function(err, patient) {
   ...
});


Is this by design or is it a bug?  The only way I can add multiple appointments between the same physician and patient is to use the Appointment model:

Appointment.create({patientId: 1, physicianId:2, appointmentDate: new Date(2017,2,2)}, callback);
Reply all
Reply to author
Forward
0 new messages