使用Bookshelfjs格式化hasMany / through关系的正确方法是什么?

时间:2017-02-19 16:18:27

标签: javascript orm jointable bookshelf.js

我无法使用Bookshelf.js制作hasMany/through关系。以下是我正在使用的具体表格:

一个术语可以有很多翻译,每个翻译都引用一个术语。

term.id - > translation.source

translation.target - > term.id

我正在尝试制作一个带有术语的查询,并通过翻译返回所有相关术语。

这就是我在我的Term课程中所拥有的:

export const Term = Model.extend({
  tableName: 'terms',

  //... other methods

  englishTranslations() {
    return this.hasMany('Term', 'id').through('Translation', 'id', 'source', 'id', 'target');
  }
});

我在select method within sync.js内遇到异常relatedData.pivotColumns undefined导致through.parse投掷。

我对如何在构建through电话时正确引用外键感到困惑,并感谢任何人提供的任何帮助。

0 个答案:

没有答案
相关问题