-
Notifications
You must be signed in to change notification settings - Fork 11.4k
[9.x] Cross-database support for all relations #46675
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
Conversation
hasManyThrough
I don't think cross-database relationships is something that is meant to be supported by the framework. |
In any case, if this is to be a new feature that is wanted, it would need to target 10.x, not 9.x. |
Imo its definitely something that needs to be supported. Eloquent already has most of the infrastructure to deal with different connections. Besides that, this fix is relatively small since it only prepends database names when connections differ. I would be fine with sending it to 10.x but I regard it as a bug since some of the functionality currently works and some doesn't. |
decided to send to 10.x instead #46769 |
Related to #23042
Issue
Various relationship methods do not work with cross database relations including
withCount
andwhereHas
. SQL errors were thrown because the database name was not prefixed in all cases. Some work has been done previously to accomplish this, however it wasn't tested thoroughly and several cases were left unconsidered (like joins and specific relation types).Requirements
MorphToMany
/BelongsToMany
relations are required to have an intermediary Eloquent model defined like so, because the connection from the intermediary table cant be resolved otherwise:Task status
morphTo()
relation, where$users->query()->withCount('morphable')->get()
results in a syntax error when no additional arguments are given to the relation (the SQL contains'laravel_reserved_0'.''
because it is missing a key). The issue is solved though once you hardcode the relation asreturn $this->morphTo(null, null, null, 'id')
. I excluded the test case from my tests it is an existing issue.Support status
dbo
was required. A custom config override'schema'
has been added in the database configuration, similar to Postgres)dblink
and/orpostgres_fdw
)