-
Notifications
You must be signed in to change notification settings - Fork 179
Description
Will elaborate later.
When digging in the code for a way to specify different prefixes for different EntityManagers (a question about prefixes was raised on slack...) I found that this used to be possible using https://github.com/bolt/core/blob/master/src/Doctrine/TablePrefix.php and https://github.com/bolt/core/blob/master/src/Doctrine/TablePrefixTrait.php
Apparently after the introduction of symfony/proxy-manager-bridge this functionality stopped working 202bd79
I think I've found a fix :-)
I did a little experiment, and found that when you do this:
protected function setTablePrefix(ObjectManager $manager, string $prefix)
{
$key = spl_object_hash($manager);
// force initializing the ObjectManager in case it is a proxy
$manager->getMetadataFactory();
$key2 = spl_object_hash($manager);
$this->tablePrefixes[$key] = Str::ensureEndsWith($prefix, '_');
return $this;
}
$key2 will have the 'correct' spl_object_hash() result.
Why? Well, the original call to spl_object_hash() was before the lazy proxy was initialized. Performing an action on the proxy will initialize it. Apparently this initialization is on a level where it actually means the spl_object_hash does change, even when the documentation of spl_object_hash() suggests to me that such a thing would not be possible.