What is the best way to get the table name from a specific object? Is there something like:
$tableName = Utility::doSomeMagic($object);
So that you get tx_extkey_domain_model_myobject from Vendor\Extkey\Domain\Model\MyObject.
You can use the DataMapper to get the table name of a model. It is used internally by the Repositories(indirectly at least) to tell what they are dealing with. You can get yourself an instance of the DataMapper and use it like so:
$className = \MyVendor\MyExt\Domain\Model\SomeModel::class;
$dataMapper = \TYPO3\CMS\Core\Utility\GeneralUtility::makeInstance(\TYPO3\CMS\Extbase\Persistence\Generic\Mapper\DataMapper::class);
$tableName = $dataMapper->getDataMap($className)->getTableName();
Take a look at the SqlDebuggerUtility from this github repository, which is using the DataMapper to get the tablename of a QueryResult object to debug the SQL statements.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With