admin管理员组文章数量:1355684
I'm using Symfony 6.4 with multiple connections. I have 2 databases (P2223 and P2324) with the same datatables struct, but with different data.
My .env:
DATABASE_URL="mysql://root:[email protected]:3306/P2223?serverVersion=8.0.39&charset=utf8mb4"
P2324="mysql://root:[email protected]:3306/P2324?serverVersion=8.0.39&charset=utf8mb4"
This is my doctrine.yaml:
# config/packages/doctrine.yaml
doctrine:
dbal:
connections:
P2324:
url: '%env(resolve:P2324)%'
logging: true
default:
url: '%env(resolve:DATABASE_URL)%'
logging: true
default_connection: P2324
orm:
default_entity_manager: P2324
entity_managers:
P2324:
connection: P2324
mappings:
Main:
is_bundle: false
dir: '%kernel.project_dir%/src/Entity'
prefix: 'App\Entity'
default:
connection: default
mappings:
Main:
is_bundle: false
dir: '%kernel.project_dir%/src/Entity'
prefix: 'App\Entity'
This is my controller:
$entityManager = $doctrine->getManager('P2324');
$item=$entityManager->getRepository(Aules::class)->findOneBy(array('id' => 1));
$item->setNom("newName");
print_r($item);
try{$entityManager->flush();}
catch(\Exception $e){
$errorMessage = $e->getMessage();
echo $errorMessage;
}
return new JsonResponse([], Response::HTTP_OK, [], false);
It works ok, but if I change the connection: $entityManager = $doctrine->getManager('default'); It doesn't works. But, surprisingly, if I change doctrine.yaml, and I change the order of connections, using $entityManager = $doctrine->getManager('default');, it works ok. Like that:
# config/packages/doctrine.yaml
doctrine:
dbal:
connections:
default:
url: '%env(resolve:DATABASE_URL)%'
logging: true
P2324:
url: '%env(resolve:P2324)%'
logging: true
default_connection: P2324
orm:
default_entity_manager: P2324
entity_managers:
default:
connection: default
mappings:
Main:
is_bundle: false
dir: '%kernel.project_dir%/src/Entity'
prefix: 'App\Entity'
P2324:
connection: P2324
mappings:
Main:
is_bundle: false
dir: '%kernel.project_dir%/src/Entity'
prefix: 'App\Entity'
So, Doctrine only detects if the object has changed if I use the first connection, but don't detect any changes if I use the second connection. Weird. How can I doctrine will update the database.
本文标签: doctrineSymfony 64 multiple connectionsupdate not always workingStack Overflow
版权声明:本文标题:doctrine - Symfony 6.4 multiple connections, update not always working - Stack Overflow 内容由网友自发贡献,该文观点仅代表作者本人, 转载请联系作者并注明出处:http://www.betaflare.com/web/1744028163a2578417.html, 本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌抄袭侵权/违法违规的内容,一经查实,本站将立刻删除。
发表评论