SequelizeJS:如何在不使用原始查询的情况下在多个数据库中包含关联(join)

时间:2015-06-09 03:38:24

标签: javascript node.js orm sequelize.js

假设DB“A”中有“Account”表,DB“B”中有“ConversationHistory”表。

我的伪初始化脚本是:

// Connection Script
var db1 = new Sequelize("A", user, password)
var db2 = new Sequelize("B", user, password)

// Association
Account.hasMany(ConversationHistory, {foreignKey: "sender_id", as: "conversations", constraints: false})
ConversationHistory.belongsTo(Account, {foreignKey: "sender_id", as: "sender", constraints: false});

// But when I use include in findMethod like
ConversationHistory.findAll({
      where: {
         ...
      },
      include: [{
          model: Account,
          where: { userId: userId },
          as: "sender"
      }]
    })

并且此findAll的结果是关于无法在数据库“B”上找到Account表的错误(它隐式使用B.Account和B.ConversationHistory,但我想使用A.Account,而不是)。

是否可以在不使用原始查询的情况下跨多个数据库进行连接?我在SequelizeJS文档中搜索了该选项,但找不到该怎么做:(

谢谢。

0 个答案:

没有答案