mirror of
https://github.com/archtechx/virtualcolumn.git
synced 2025-12-12 08:04:04 +00:00
Sync with original attributes
This commit is contained in:
parent
41d300bf7f
commit
2ae1ed099f
2 changed files with 5 additions and 0 deletions
|
|
@ -30,6 +30,7 @@ trait VirtualColumn
|
|||
|
||||
foreach ($model->getAttribute(static::getDataColumn()) ?? [] as $key => $value) {
|
||||
$model->setAttribute($key, $value);
|
||||
$model->syncOriginalAttribute($key);
|
||||
}
|
||||
|
||||
$model->setAttribute(static::getDataColumn(), null);
|
||||
|
|
@ -52,6 +53,7 @@ trait VirtualColumn
|
|||
]));
|
||||
|
||||
unset($model->attributes[$key]);
|
||||
unset($model->original[$key]);
|
||||
}
|
||||
}
|
||||
|
||||
|
|
|
|||
|
|
@ -34,6 +34,7 @@ class VirtualColumnTest extends TestCase
|
|||
// Model has the correct structure when retrieved
|
||||
$model = MyModel::first();
|
||||
$this->assertSame('bar', $model->foo);
|
||||
$this->assertSame('bar', $model->getOriginal('foo'));
|
||||
$this->assertSame(null, $model->data);
|
||||
|
||||
// Model can be updated
|
||||
|
|
@ -43,7 +44,9 @@ class VirtualColumnTest extends TestCase
|
|||
]);
|
||||
|
||||
$this->assertSame('baz', $model->foo);
|
||||
$this->assertSame('bar', $model->getOriginal('foo'));
|
||||
$this->assertSame('xyz', $model->abc);
|
||||
$this->assertSame('xyz', $model->getOriginal('abc'));
|
||||
$this->assertSame(null, $model->data);
|
||||
|
||||
// Model can be retrieved after update & is structure correctly
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue