1

I am trying to access a target model and its related models in a hasManyThrough setup in Loopback 4. For example in the documentation:

https://loopback.io/doc/en/lb4/HasManyThrough-relation.html

how do I get all appointments of a specific doctor with the patient data included?

When I try to access /doctors (with exact same setup in the above article) with the following filter:

const filter = {
  include: [
    { relation: 'patients' },
]};

I do get to see the list of patients.

However, I'd like access /doctors with the following filter:

   const filter = {
      include: [
        { relation: 'appointments',
          scope: {
            include: [{relation: 'patient'}],
          },
        },
      ]
    };

Is there a way the hasManyThrough relationship supports this? Or do I need to connect my models differently through custom logic instead.

xfscrypt
  • 16
  • 5
  • 28
  • 59
  • In your first one you say `relation: 'patients'` and in your second you say `relation: 'patient'` (`patient` vs. `patientS`). Is that intentional? –  Nov 27 '21 at 01:01
  • To echo @user17242583, was the relation name difference intentional? Furthermore, if `scope` is not necessary, the `include` filter could be simplified to `include:['patient']`. – Rifa Achrinza Dec 12 '21 at 17:12
  • Also, would it be possible to provide the code of the models and repository? This would make us to better-understand the setup. – Rifa Achrinza Dec 12 '21 at 17:14

0 Answers0