Skip to content

Commit f5b12bd

Browse files
committed
disable null values for indexed fields
1 parent cf4ab64 commit f5b12bd

File tree

2 files changed

+35
-1
lines changed

2 files changed

+35
-1
lines changed

src/Repository.php

Lines changed: 13 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -263,10 +263,22 @@ public function save($instance)
263263
{
264264
$tuple = [];
265265

266+
$format = $this->space->getFormat();
267+
268+
// complete indexes fields
269+
foreach($this->space->getIndexes() as $index) {
270+
foreach($index->parts as $part) {
271+
$name = $format[$part[0]]['name'];
272+
if(!property_exists($instance, $name)) {
273+
$instance->{$name} = null;
274+
}
275+
}
276+
}
277+
266278
$size = count(get_object_vars($instance));
267279
$skipped = 0;
268280

269-
foreach($this->space->getFormat() as $index => $info) {
281+
foreach($format as $index => $info) {
270282
if(!property_exists($instance, $info['name'])) {
271283
$skipped++;
272284
$instance->{$info['name']} = null;

tests/MapperTest.php

Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,28 @@
77

88
class MapperTest extends TestCase
99
{
10+
public function testNullIndexedValuesFilling()
11+
{
12+
$mapper = $this->createMapper();
13+
$this->clean($mapper);
14+
15+
$mapper->getSchema()
16+
->createSpace('rules', [
17+
'id' => 'unsigned',
18+
'module' => 'unsigned',
19+
'rule' => 'unsigned',
20+
])
21+
->addIndex('id')
22+
->addIndex('module')
23+
->addIndex('rule');
24+
25+
$rule = $mapper->create('rules', [
26+
'id' => 1,
27+
'module' => 1
28+
]);
29+
$this->assertSame($rule->rule, 0);
30+
}
31+
1032
public function testTypesCasting()
1133
{
1234
$mapper = $this->createMapper();

0 commit comments

Comments
 (0)