R
R
Roman2020-07-11 18:52:40
ORM
Roman, 2020-07-11 18:52:40

How to create a table via ORM in an additional database connected to Bitrix?

Hello!

It was necessary to connect an additional database to Bitrix.

To create a table in an additional database, I wanted to use the Bitrix\Main\Entity\Base class:

use Bitrix\Main\Application;
use Ramapriya\ORM;
use Bitrix\Main\Entity\Base;

$dbApps = Application::getConnection('apps');

$base = Base::getInstance(ORM\ApplicationTable::class);

$tableName = $base->getDBTableName();

if(!$dbApps->isTableExists($tableName)) {
    $base->createDbTable($tableName);
}


However, then it turned out that the table was created in the main database.

Tell me, is there a way to create a table in an additional database from an ORM class, or do I need to use other methods?

Answer the question

In order to leave comments, you need to log in

1 answer(s)
P
pavelkrd, 2021-04-21
@pavelkrd

If it is necessary to use another database connection for the ORM table, then in the class it is necessary to define the static getConnectionName method, which returns a string with the connection name

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question