Can not configure table name
gubler opened this issue · comments
I have a database that I have to share with other applications in production. I need to be able to customize the name of the table using the bundle configuration.
I'll try to create a PR for this, but I don't know when I'll have the chance. Wanted to submit it to get any feedback or suggestions before I started work on this feature.
Hello @gubler,
You may configure the table name via doctrine EventSubscriber in your app.
<?php
namespace App\EventSubscriber;
use Doctrine\Common\EventSubscriber;
use Doctrine\ORM\Event\LoadClassMetadataEventArgs;
use Doctrine\ORM\Events;
use JMose\CommandSchedulerBundle\Entity\ScheduledCommand;
class ModifyTableSubscriber implements EventSubscriber
{
public function getSubscribedEvents(): array
{
return [
Events::loadClassMetadata,
];
}
public function loadClassMetadata(LoadClassMetadataEventArgs $args): void
{
$classMetadata = $args->getClassMetadata();
if ($classMetadata->getName() !== ScheduledCommand::class) {
return;
}
$classMetadata->setPrimaryTable(['name' => 'my_scheduled_command']);
}
}
And register this as service with tag
services:
# ...
App\EventSubscriber\ModifyTableSubscriber:
tags: [{ name: doctrine.event_subscriber }]
Hope this helps :)
Well... that's much simpler. Thank you.