Skip to content

Commit 643420e

Browse files
committed
reduce non-required properties default values set
1 parent b12ae2b commit 643420e

File tree

2 files changed

+7
-0
lines changed

2 files changed

+7
-0
lines changed

src/Repository.php

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -183,6 +183,8 @@ public function save($instance)
183183
{
184184
$tuple = [];
185185

186+
$size = count(get_object_vars($instance));
187+
186188
foreach($this->space->getFormat() as $index => $info) {
187189
if(!property_exists($instance, $info['name'])) {
188190
$instance->{$info['name']} = null;
@@ -191,6 +193,10 @@ public function save($instance)
191193
$instance->{$info['name']} = $this->space->getMapper()->getSchema()
192194
->formatValue($info['type'], $instance->{$info['name']});
193195
$tuple[$index] = $instance->{$info['name']};
196+
197+
if(count($tuple) == $size) {
198+
break;
199+
}
194200
}
195201

196202
$key = $this->space->getInstanceKey($instance);

tests/SchemaTest.php

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -76,6 +76,7 @@ public function testBasics()
7676
$this->assertSame($nekufa->id, 1);
7777
$this->assertSame($nekufa->name, 'nekufa');
7878
$this->assertSame($nekufa->birthday, 19840127);
79+
$this->assertFalse(property_exists($nekufa, 'gender'));
7980

8081
$person = $mapper->findOne('person', ['birthday' => '19840127']);
8182
$this->assertSame($person, $nekufa);

0 commit comments

Comments
 (0)