-
Notifications
You must be signed in to change notification settings - Fork 3.4k
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
3.0 - Associations and different connections #5369
Comments
You'll have to set the strategy on your belongsTo to use the 'select' strategy. As cross datasource joins are not supported right now. |
Thanks @markstory, that did it! |
Another way is to call table() in the initialize method with the full table name including the database name prefix |
I tried that actually but it still got confused with the i18n stuff. |
Ah ok, that requires a bit of clever changes. Like creating your own i18n object in the registry |
Actually, today I needed to get i18n from a connection other than default and it's a little buggy. It looks like
default connection schema:
custom connection schema:
This happens even if I set the
Adding the scope field to the custom connection works, and I get the correct translated data, although I think this schema mixup is a bug. |
A much easier way to have described the bug I'm seeing is that if your default connection has no i18n table, it'll error out even though your Table is using a custom connection. When trying to do a find, cake is trying to do the following without a context for which connection it should be using:
|
Well there is only 1 I18n table object, and if it is undefined it will use 'default' connection. Do you have i18n tables in multiple connections? |
Hm, where is that I18nTable? I have multiple i18n tables in different connections, yes. I tried creating a
I don't know how else I could have a single I18nTable, unless you'd allow specifying the connection like:
|
The default table alias name is |
But right now I can't change that on a per-Table basis, right? I can specify a different table but the framework doesn't know which connection to get its schema from, it always uses the default connection's schema. |
After looking at this more, it looks like the right way to do it is to change the fundamental way the i18n table is declared. If you allow specifying the translated table class instead of the table name, and edit the core
Then in that class, define stuff..
|
@patrickconroy That sounds like a good idea to me. Would you be able to make a pull request for this change? |
@markstory, I started this at patrickconroy@d3f3533 , but I've gotten to a point where I don't know which function is supposed to be merging the results found in the i18n table back to the main record. The
|
That's _rowMapper. If you inject a
You will probably be able to see the wizard behind the curtain. |
I tried debugging in there, but the translated fields are NULL, so they're skipped when this happens:
The fields shouldn't be NULL, though..
|
Oh extra pointer:
I believe you are currently calling |
Hm, yeah in my Controller I have..
(updated the debug from _rowMapper) |
I took a closer look at what you've done. Here's a gist for direct comparison: https://gist.github.com/AD7six/971b4773e7819277449f The The problem is related to this: |
I don't get how that's possible. Shouldn't |
@patrickconroy are you able to follow up with the proposed changes? Let us know if you need help |
I updated the TranslateBehavior @ patrickconroy@2bea4c1 with the changes that will make this work. Let me know if I should make a PR for that (it kind of diverges from the subject of this issue - it's to allow setting Tables for I18n purposes). Thanks |
Yeas, please. Make it a PR |
Closing as the PR for translate behavior was merged |
If I have the following setup:
And I try to get
Items
..It errors out, complaining that the
Posts
table does not exist in thecustom
connection. Am I doing something wrong? I thought there might be a way to specify the connection in the association directly..$this->belongsTo('Posts', ['connection' => ['default']);
but there isn't. And I really don't think I should need to specify
default
as the connection forPosts
, as I'd expect Tables to usedefault
by default even if their parent uses a custom one.It will also error out if my
Posts
table is translated, since the Query doesn't know that my i18n table isn't in my custom connection, it's in the default one.Is there a DataSource config option to make every Table use their connection's DB as a prefix? That would halfway solve this, but the i18n issue would still happen.
Thanks.
The text was updated successfully, but these errors were encountered: