New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Multiple Database Association #13808
Comments
This issue has been automatically marked as stale because it has been open for 14 days without activity. It will be closed if no further activity occurs within the next 14 days. If this is still an issue, just leave a comment or remove the "stale" label. 🙂 |
We don't have enough information to help you with this, please provide a SSCCE that replicates your problem. Are you trying to join two tables that are in different databases (as in servers) or different schemas? |
Yeah, I try to join two tables in different schema in same serve, not distributed server schema. |
@codecnmc that's indeed awesome,as for now you may need to include it your business logic |
I have been using modified sequelize for some time now with multiple databases and associations. All it takes to fix sequelize is couple lines of code at if (this._dialect.supports.schemas) {
if (param.schema) {
if (param.schema.split(".").length === 2) { //<------------------------ starts here
const [databaseName, schemaName] = param.schema.split(".")
table += `[${databaseName}].[${schemaName}].`;
} else { //<-------------------------------------------------------------- ends here
table += `${this.quoteIdentifier(param.schema)}.`;
}
}
table += this.quoteIdentifier(param.tableName);
} then all you have to do is to add database name to your model's schema like this: {
tableName: "users",
schema: "databaseName.schema",
} and end query will look like this: FROM [databaseName].[schema].users All cross database associations will work perfectly :-) |
Issue Creation Checklist
Feature Description
Different database to association.
Is your feature request related to a problem? Please describe.
I try to different database to association.
Immediate to association in model associate is unuseful ,Sequelize tips another database model is undefined.
Try to use setTimeout function to delay belongsTo function is called,Sequelize success init not tips any error.I check database foreign keys is not created.I try to call interface but sequelize tips Table 'xxxx.xxxxx' doesn't exist"
Describe the solution you'd like
sequelize create query
but correct query is
I hope different database to association come true
thank you
Why should this be in Sequelize
New database maybe depend on another database table,But always use raw queries to left inner join query is too slow,Every time need to think about this query statement or double query find A and then find where xxx:A.xxx in B
Describe alternatives/workarounds you've considered
Additional context
Feature Request Checklist
Is this feature dialect-specific?
Would you be willing to implement this feature by submitting a Pull Request?
The text was updated successfully, but these errors were encountered: