Skip to content

Commit e5bee0e

Browse files
author
Ethan Hann
committed
Merge branch 'bug/add_many_referencing_property_object'
2 parents d96e51b + 1fa3ef6 commit e5bee0e

File tree

2 files changed

+19
-1
lines changed

2 files changed

+19
-1
lines changed

src/Index.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -68,7 +68,7 @@ protected function getFields(): array
6868
$fields = [];
6969
foreach (get_object_vars($this) as $field) {
7070
if ($field instanceof FieldInterface) {
71-
$fields[$field->getName()] = $field;
71+
$fields[$field->getName()] = clone $field;
7272
}
7373
}
7474
return $fields;

tests/RediSearch/IndexTest.php

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -502,4 +502,22 @@ public function testSetStopWordsOnCreateIndex()
502502
$result = $this->subject->search('Jack');
503503
$this->assertEquals(1, $result->getCount());
504504
}
505+
506+
public function testShouldNotChangeOriginalSchemaFieldWhenAddingNewDocument()
507+
{
508+
$expectedId = 'id1';
509+
$expectedTitle = 'Foo';
510+
$documents = [];
511+
$newDocument = $this->subject->makeDocument();
512+
$newDocument->setId($expectedId);
513+
$newDocument->title->setValue($expectedTitle);
514+
$documents[] = $newDocument;
515+
516+
$barDocument = $this->subject->makeDocument();
517+
$barDocument->setId('id2');
518+
$barDocument->title->setValue('Bar');
519+
520+
$this->assertEquals($expectedId, $documents[0]->getId());
521+
$this->assertEquals($expectedTitle, $documents[0]->title->getValue());
522+
}
505523
}

0 commit comments

Comments
 (0)