Objective JS 从 joined table + filter 中获取额外的属性

Objection JS get extra properties from joined table + filter

我有以下型号:

class Profile extends Model {

.......................

  static relationMappings = {
    finishers: {
      relation: Model.ManyToManyRelation,
      modelClass: Move,
      filter: (query) => query.select('move.id', 'move.type'),
      join: {
        from: 'profile.id',
        through: {
          from: 'profile_move.profile_id',
          to: 'profile_move.move_id',
          extra: {
            alternative_name: 'name',
          },
        },
        to: 'move.id',
      },
    },
  };
}

我想做的是只从 move table 中获取 move.id & move.type 以及额外的 属性 nameprofile_move 加入了 table。问题是如果我使用 filter 或修饰符它 returns 只有 move.id & move.type 而不是额外的 属性.

路线:

router.get('/', async (req, res, next) => {
  try {
    const data = await Profile.query()
      .orderBy('id')
      .withGraphFetched('finishers');

    res.json(data);
  } catch (error) {
    next(error);
  }
});

解决方案是将额外的属性传递给过滤器:

filter: (query) => query.select('move.id', 'move.type', 'profile_move.name'),