When loading entities with the same ID from two tenants, same entity is returned - the one from the first tenant. It appears that when dispatching a switch event, TenantEntityManager's identity map is not cleared, so all entities that were loaded while working with the first tenant remain. This means that, if entities with same IDs are requested from the tenant entity manager, the existing ones - from the previous tenant - will get returned. Example:
$switchEvent = new SwitchDbEvent(1);
$dispatcher->dispatch($switchEvent);
$product = $tem->getRepository(Product::class)->find(3);
$switchEvent = new SwitchDbEvent(2);
$dispatcher->dispatch($switchEvent);
$product2 = $tem->getRepository(Product::class)->find(3);
Both $product1 and $product2 are returned as the same product, even though they are completely different in the two databases. I can get around this by calling $tem->clear() after dispatching a switch event, but I feel that this should happen automatically. Can't see any circumstances where keeping entities of frist tenant cached around while working with another tenant would be useful (and not dangerous instead).
When loading entities with the same ID from two tenants, same entity is returned - the one from the first tenant. It appears that when dispatching a switch event, TenantEntityManager's identity map is not cleared, so all entities that were loaded while working with the first tenant remain. This means that, if entities with same IDs are requested from the tenant entity manager, the existing ones - from the previous tenant - will get returned. Example:
Both $product1 and $product2 are returned as the same product, even though they are completely different in the two databases. I can get around this by calling
$tem->clear()
after dispatching a switch event, but I feel that this should happen automatically. Can't see any circumstances where keeping entities of frist tenant cached around while working with another tenant would be useful (and not dangerous instead).