Skip to content

Commit c5e70e8

Browse files
authoredJan 4, 2022
Merge pull request #7 from stein-j/master
Sync with original attributes
2 parents 41d300b + 9b31176 commit c5e70e8

File tree

2 files changed

+5
-0
lines changed

2 files changed

+5
-0
lines changed
 

‎src/VirtualColumn.php

+2
Original file line numberDiff line numberDiff line change
@@ -30,6 +30,7 @@ protected static function decodeVirtualColumn(self $model): void
3030

3131
foreach ($model->getAttribute(static::getDataColumn()) ?? [] as $key => $value) {
3232
$model->setAttribute($key, $value);
33+
$model->syncOriginalAttribute($key);
3334
}
3435

3536
$model->setAttribute(static::getDataColumn(), null);
@@ -52,6 +53,7 @@ protected static function encodeAttributes(self $model): void
5253
]));
5354

5455
unset($model->attributes[$key]);
56+
unset($model->original[$key]);
5557
}
5658
}
5759

‎tests/VirtualColumnTest.php

+3
Original file line numberDiff line numberDiff line change
@@ -34,6 +34,7 @@ public function keys_which_dont_have_their_own_column_go_into_data_json_column()
3434
// Model has the correct structure when retrieved
3535
$model = MyModel::first();
3636
$this->assertSame('bar', $model->foo);
37+
$this->assertSame('bar', $model->getOriginal('foo'));
3738
$this->assertSame(null, $model->data);
3839

3940
// Model can be updated
@@ -43,7 +44,9 @@ public function keys_which_dont_have_their_own_column_go_into_data_json_column()
4344
]);
4445

4546
$this->assertSame('baz', $model->foo);
47+
$this->assertSame('baz', $model->getOriginal('foo'));
4648
$this->assertSame('xyz', $model->abc);
49+
$this->assertSame('xyz', $model->getOriginal('abc'));
4750
$this->assertSame(null, $model->data);
4851

4952
// Model can be retrieved after update & is structure correctly

0 commit comments

Comments
 (0)
Please sign in to comment.