Skip to content

Prepend database to table name (Cross database joins) #2049

Description

@fibers

It seems that the sequelize doesn't support the join across databases in the same server.

db.UserReport.findAll({
            include: [
                {model: db.User, as: 'User'},
                {model: db.Report, as: 'Report'}
            ]
});

database: A
table: user_report
database: B
table: user , report

UserReport is a relevance table contains a user_id and report_id.
Sequelize only append the database name on the main table.
For the above case , it will generate the sql like " select A.user_report.user_id ..... from A.user_report left join user on A.user_report.user_id = user.user_id ... ...", so it will raise a error saying " table 'user' doesn't exists"

Activity

  1. changed the title [-]Request for adding the database name in generated sql to implement the join across databases[/-] [+]Prepend database to table name (Cross database joins)[/+] on Jul 5, 2016
  2. Naoto-Ida commented on Jul 21, 2016

    @Naoto-Ida

    I'm having the exact same issue with MYSQL, not MSSQL.

    I have two databases that are on the same server.
    Joining them in a statement is essential for our API, and I think this is needed by many people.

  3. foysalit commented on Dec 14, 2018

    @foysalit

    I would love to help out and get this implemented. @sushantdhiman can you or any one of the contributors point me to the right directions to get started? some clues would be helpful.

  4. valoupeca commented on Jun 20, 2019

    @valoupeca

    Hello, any update about this issue ? I've got 2 databases in Postgres and i can't associate User fromdatabase1 with Profil from database2

  5. biruks commented on Aug 9, 2019

    @biruks

    Any update on this?

  6. papb commented on Aug 9, 2019

    @papb
    Member

    @biruks #10281 is WIP for mysql for this.

  7. Rajat117 commented on Jan 22, 2020

    @Rajat117

    Anu updates on this issue

  8. eleezs commented on Jan 3, 2024

    @eleezs

    I am having the same problem on Postgres. Any update yet?

  9. added theissue type on Mar 9, 2025
  10. removed
    type: feature
    on Mar 9, 2025
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions