I think the resources is relating to the actual database connection. M1 in the past had something like this:
<resources>
<backup_setup>
<setup>
<module>Mage_Backup</module>
</setup>
<connection>
<use>core_setup</use>
</connection>
</backup_setup>
<backup_write>
<connection>
<use>core_write</use>
</connection>
</backup_write>
<backup_read>
<connection>
<use>core_read</use>
</connection>
</backup_read>
</resources>
so I would say the resources file is the successor to what the connection was.
Not sure that the _setup node provides much value above the other line as we have this code in
lib/internal/Magento/Framework/App/ResourceConnection/Config.php
public function getConnectionName($resourceName)
{
$connectionName = \Magento\Framework\App\ResourceConnection::DEFAULT_CONNECTION;
$resourceName = preg_replace("/_setup$/", '', $resourceName);
and also in setup/src/Magento/Setup/Module/Setup/ResourceConfig.php
class ResourceConfig implements \Magento\Framework\App\ResourceConnection\ConfigInterface
{
/**
* {@inheritdoc}
*/
public function getConnectionName($resourceName)
{
return \Magento\Framework\App\ResourceConnection::DEFAULT_CONNECTION;
}
}
I had a quick look through some of the enterprise modules to see if that sheds more light on the use of the resources.xml
file (as multiple dbs is apparently an M2 Enterprise feature) but the only use that I have come across so far also only uses extends from core
.
My hunch is that one would need to create additional db connections in app/etc/env.php
which then allows you to use those values to override the ones shipped in the default resource.xml
files (ie just the 1 default connection).
Best Answer
I was looking for the same solution and came across this:
https://blog.hauri.me/magento2-custom-database-connection.html
I didn't implement the resource model part since I don't need it now but the following part helped me a lot.
/** @var Magento\Framework\App\ResourceConnection $this->resourceConnection **/ $connection = $this->resourceConnection->getConnection('custom');
I use it my code like this (this is part of controller for test purposes) in my code to get a custom connection
All the rest just like in here https://www.maxpronko.com/blog/new-database-connection-in-magento-2
I hope this helps!