首页 > 解决方案 > ObjectionJS:在两个子字段上的 HasMany 关系

问题描述

我目前正在使用 Objection 从 SQL 查询中获取不错的对象。

我有这样的比赛:

id integer primary key,
teamA integer references(teams.id),
teamB integer references(teams.id),

scoreA integer,
scoreB integer

我的 ObjectionTeam类中有没有办法指定我的团队有matches, 所以HasMany关系,但可以在两个字段中找到。

  static get relationMappings() {
    return {
      matches: {
        relation: Model.HasManyRelation,
        modelClass: Match,
        join: {
          from: ['matches.teamA', 'matches.teamB'],
          to: 'teams.id',
        }
      }
    };
  }

提前致谢

标签: sqlnode.jspostgresqlobjection.js

解决方案


推荐阅读