Как я могу включить массив модели? - PullRequest
0 голосов
/ 22 марта 2020
var user = await db.user.findOne({
      attributes: attributes,
      include: ['charges',
        'availability',
        'practice',// 'services',
        'education',// 'user_role',
        'address',
        'user_location',
        // 'isAvailableStatus',
        { model: db.user_role, attributes: role_attributes },
        {
          model: db.user_service, as: 'services',
          //        ThIS IS MY QUESTION
          include : [db.service_group, as : 'group']
          //
        },
      ],
      where: {id: 0}
    });

Пользователь -> user_role-> один из user_role # Это работает
Пользователь -> user_service-> массив service_group # это не работает // мой вопрос

screen

Как включить массив моделей?

1 Ответ

1 голос
/ 24 марта 2020

Вам нужно изменить свой код следующим образом. Если вы правильно определили ассоциации, то получите ожидаемый результат.

var user = await db.user.findOne({
  attributes: {
    include: [
      'charges',
      'availability',
      'practice', // 'services',
      'education', // 'user_role',
      'address',
      'user_location'
      // 'isAvailableStatus',
    ]
  },
  include: [
    { model: db.user_role, attributes: role_attributes },
    {
      model: db.user_service,
      as: 'services',
      include: [{ model: db.service_group, as: 'group' }]
    }
  ],
  where: { id: 0 }
});

Надеюсь, это поможет!

...