mirror of
https://github.com/danog/AsyncOrm.git
synced 2024-11-26 20:34:55 +01:00
Final fixes
This commit is contained in:
parent
8add7e504c
commit
48237a5419
@ -40,6 +40,7 @@ use function Amp\Future\await;
|
|||||||
*/
|
*/
|
||||||
abstract class DriverArray extends DbArray
|
abstract class DriverArray extends DbArray
|
||||||
{
|
{
|
||||||
|
private bool $inited = false;
|
||||||
/**
|
/**
|
||||||
* @param Serializer<TValue> $serializer
|
* @param Serializer<TValue> $serializer
|
||||||
*/
|
*/
|
||||||
@ -47,21 +48,26 @@ abstract class DriverArray extends DbArray
|
|||||||
protected readonly FieldConfig $config,
|
protected readonly FieldConfig $config,
|
||||||
protected readonly Serializer $serializer
|
protected readonly Serializer $serializer
|
||||||
) {
|
) {
|
||||||
|
$this->inited = true;
|
||||||
}
|
}
|
||||||
|
|
||||||
public static function getInstance(FieldConfig $config, DbArray|null $previous): DbArray
|
public static function getInstance(FieldConfig $config, DbArray|null $previous): DbArray
|
||||||
{
|
{
|
||||||
|
$migrate = true;
|
||||||
if ($previous !== null
|
if ($previous !== null
|
||||||
&& $previous::class === static::class
|
&& $previous::class === static::class
|
||||||
&& $previous->config == $config
|
&& $previous->config == $config
|
||||||
) {
|
) {
|
||||||
return $previous;
|
if ($previous->inited) {
|
||||||
|
return $previous;
|
||||||
|
}
|
||||||
|
$migrate = false;
|
||||||
}
|
}
|
||||||
\assert($config->settings instanceof DriverSettings);
|
\assert($config->settings instanceof DriverSettings);
|
||||||
|
|
||||||
$instance = new static($config, $config->settings->serializer);
|
$instance = new static($config, $config->settings->serializer);
|
||||||
|
|
||||||
if ($previous === null) {
|
if ($previous === null || !$migrate) {
|
||||||
return $instance;
|
return $instance;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -383,7 +383,11 @@ final class OrmTest extends TestCase
|
|||||||
$this->assertSame(1, $obj->saveBeforeCnt);
|
$this->assertSame(1, $obj->saveBeforeCnt);
|
||||||
|
|
||||||
$obj->arr[12345] = 54321;
|
$obj->arr[12345] = 54321;
|
||||||
|
$obj->arr2[123456] = 654321;
|
||||||
$this->assertSame(54321, $obj->arr[12345]);
|
$this->assertSame(54321, $obj->arr[12345]);
|
||||||
|
$this->assertSame(654321, $obj->arr2[123456]);
|
||||||
|
$this->assertCount(1, $obj->arr);
|
||||||
|
$this->assertCount(1, $obj->arr2);
|
||||||
|
|
||||||
$obj = $orm[321];
|
$obj = $orm[321];
|
||||||
|
|
||||||
@ -391,6 +395,9 @@ final class OrmTest extends TestCase
|
|||||||
$this->assertSame(1, $obj->saveAfterCnt);
|
$this->assertSame(1, $obj->saveAfterCnt);
|
||||||
$this->assertSame(1, $obj->saveBeforeCnt);
|
$this->assertSame(1, $obj->saveBeforeCnt);
|
||||||
$this->assertSame(54321, $obj->arr[12345]);
|
$this->assertSame(54321, $obj->arr[12345]);
|
||||||
|
$this->assertSame(654321, $obj->arr2[123456]);
|
||||||
|
$this->assertCount(1, $obj->arr);
|
||||||
|
$this->assertCount(1, $obj->arr2);
|
||||||
|
|
||||||
unset($obj);
|
unset($obj);
|
||||||
$orm = $field->build();
|
$orm = $field->build();
|
||||||
@ -400,6 +407,9 @@ final class OrmTest extends TestCase
|
|||||||
$this->assertSame(0, $obj->saveAfterCnt);
|
$this->assertSame(0, $obj->saveAfterCnt);
|
||||||
$this->assertSame(0, $obj->saveBeforeCnt);
|
$this->assertSame(0, $obj->saveBeforeCnt);
|
||||||
$this->assertSame(54321, $obj->arr[12345]);
|
$this->assertSame(54321, $obj->arr[12345]);
|
||||||
|
$this->assertSame(654321, $obj->arr2[123456]);
|
||||||
|
$this->assertCount(1, $obj->arr);
|
||||||
|
$this->assertCount(1, $obj->arr2);
|
||||||
|
|
||||||
$orm[321] = $obj;
|
$orm[321] = $obj;
|
||||||
|
|
||||||
@ -407,6 +417,9 @@ final class OrmTest extends TestCase
|
|||||||
$this->assertSame(0, $obj->saveAfterCnt);
|
$this->assertSame(0, $obj->saveAfterCnt);
|
||||||
$this->assertSame(0, $obj->saveBeforeCnt);
|
$this->assertSame(0, $obj->saveBeforeCnt);
|
||||||
$this->assertSame(54321, $obj->arr[12345]);
|
$this->assertSame(54321, $obj->arr[12345]);
|
||||||
|
$this->assertSame(654321, $obj->arr2[123456]);
|
||||||
|
$this->assertCount(1, $obj->arr);
|
||||||
|
$this->assertCount(1, $obj->arr2);
|
||||||
|
|
||||||
$f = new ReflectionProperty(ObjectArray::class, 'cache');
|
$f = new ReflectionProperty(ObjectArray::class, 'cache');
|
||||||
$f->getValue($orm)->flushCache();
|
$f->getValue($orm)->flushCache();
|
||||||
|
@ -25,6 +25,11 @@ final class TestObject extends DbObject
|
|||||||
ValueType::INT
|
ValueType::INT
|
||||||
)]
|
)]
|
||||||
public DbArray $arr;
|
public DbArray $arr;
|
||||||
|
#[OrmMappedArray(
|
||||||
|
KeyType::INT,
|
||||||
|
ValueType::INT
|
||||||
|
)]
|
||||||
|
public DbArray $arr2;
|
||||||
|
|
||||||
public function __sleep()
|
public function __sleep()
|
||||||
{
|
{
|
||||||
|
Loading…
Reference in New Issue
Block a user