小编Mit*_*pky的帖子

Bookshelf.js,查询相关表

我有一个类似于以下的模型:

var ScholarlyPaper = Bookshelf.Model.extend({

  tableName: 'papers',

  paragraphs: function() {
    return this.hasMany(Paragraph).through(Section);
  },

  sections: function() {
    return this.hasMany(Section);
  }

});

var Section = Bookshelf.Model.extend({

  tableName: 'sections',

  paragraphs: function() {
    return this.hasMany(Paragraph);
  }

  scholarlyPaper: function() {
    return this.belongsTo(ScholarlyPaper);
  }

});

var Paragraph = Bookshelf.Model.extend({

  tableName: 'paragraphs',

  section: function() {
    return this.belongsTo(Section);
  },

  scholarlyPaper: function() {
    return this.belongsTo(ScholarlyPaper).through(Section);
  },

  author: function() {
    return this.belongsTo(Author);
  }

});

var Author = Bookshelf.Model.extend({

  tableName: 'authors',

  paragraphs: function() {
    return this.hasMany(Paragraph);
  }

});
Run Code Online (Sandbox Code Playgroud)

使用Bookshelf.js,给定一个学术论文ID和作者ID,我如何得到论文中作者没有写一个段落的所有部分?

我面临的特殊挑战是我没有办法在相关的表上添加where子句(例如'where paragraphs.author_id!= …

node.js bookshelf.js knex.js

6
推荐指数
1
解决办法
8495
查看次数

标签 统计

bookshelf.js ×1

knex.js ×1

node.js ×1