Closed tobz-nz closed 9 years ago
This is how the Eloquent docs say to handle this (in the Specifying The Query Connection section):
Entries::on('ee')->find(1);
Yeah, I tried that, it doesn't seem to work.
In the meantime, I've swapped my default connection around, so default is 'ee' and then in my none EE models I'm setting the $connection to 'mysql'.
This approach is working, not ideal though. It'd be nice to have a config item or something for the connection to use for all Deep queries.
oh wait... on()
is working now. hmm not sure what happened there.
Never mind then.
.. may have spoken too soon.
I think it works the the first level, but any subsequent queries - eg getting file field data - do not inherit the connection name.
You're right, on
won't work. I'll have to come up with some way to set the connection global for all of Deep's models.
I just bumped to version 1.1.2, which contains the ability to set the connection globally via config. Added a note to the Readme at the bottom of this section: https://github.com/rsanchez/Deep#laravel
So in your case you'd add this to your app/config/database.php
:
'deep' => array(
'connection' => 'ee',
),
oh sweet. thanks mate. Will give it a go tomorrow.
hmm, the new config doesn't seem to be working. getting sql errors:
Table 'fusion.channels' doesn't exist (SQL: select * from `channels`)
My main problem is that all my EE tables are prefixed with exp_ as per default. but my none EE tables are not. (this is a kind of bastard hybrid app that is slowly migrating away from EE)
Take a look here: https://github.com/rsanchez/Deep/blob/master/src/App/Laravel/ServiceProvider.php#L17-L20
That's where the global connection for Deep gets set. Maybe check if the config item database.deep.connection is actually getting picked up there? That config should go in your database.php.
aha, found me problem - hadn't added teh service provider to app.php. #derp All working now. Thanks for adding that feature in so quickly, really appreciated :)
... one thing - I'm having to force the version to 1.1.2 in composer.json to get it. ~1.1 (or 1.1.*) doesn't pull in 1.1.2 which it should.
In an empty dir i tested composer require "rsanchez/deep" "~1.1"
and it installed v 1.1.2. So I'll chalk that up to composer caching weirdness or a momentary packagist snafu.
sweet as. .. just remembered I'm using a Toran Proxy instance on this project so it's probably to do with that.
I thought this should work:
Entries::setConnection('ee');
but no go. I could probably extend the Entries model and add a$connection
parameter, but that seems a bit hacky.Any ideas?