如何包含仅连接到数组中一项的模型?

How do I include a model connected to only one item in the array?

我有一条路线从属于彼此的多个模型中拉出。 制作 > 放映 > 座位、门票 > X(其中门票有许多 X)。

如何设置我的路线以将信息 X 作为票据下的对象获取?

这是我当前工作的代码,没有 X

的 'include'
router.get('/', async (req, res) => {
  try {
    const productionData = await Production.findAll({
      include: [{
        model: Showing,
        include: [Seat, Ticket]
      }]
    })
    console.log("Production Daeta", productionData)
    res.status(200).json(productionData)
  } catch (err) {
    res.status(500).json(err)
  }  
});

在不进一步了解您的问题的情况下,您应该根据需要进行嵌套。

 const productionData = await Production.findAll({
  include: [
    {
      model: Showing,
      include: [
        { model: Seat },
        {
          model: Ticket,
          include: [
            {
              model: X,
            },
          ],
        },
      ],
    },
  ],
});

这样所有的嵌套都会被返回。 一个小通知是,这将是一个相当繁重的查询,添加

可能会有用

seperate: true

在查询中有很多联接的某个时刻。