4

Suppose, there is "Account" table in DB "A", and there is "ConversationHistory" table in DB "B".

My pseudo initialized script is:

// 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"
      }]
    })

and the result of this findAll is an error about cannot find Account table on database "B" (it implicitly uses B.Account and B.ConversationHistory, but I want to use A.Account, instead).

Is it possible to join across multiple databases without using raw query ? I have searched the option on the SequelizeJS docs, but cannot find how to do it :(

Thank you.

heartmon
  • 1,411
  • 2
  • 13
  • 14

0 Answers0