Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion ORM/Manager.php
Original file line number Diff line number Diff line change
Expand Up @@ -101,7 +101,7 @@ public function persist(DocumentInterface $object)
$document = $this->convertToArray($object, $repository['getters']);

$this->getConnection()->bulk(
'create',
'index',
$repository['type'],
$document
);
Expand Down
2 changes: 0 additions & 2 deletions Tests/Functional/ORM/ManagerTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -50,8 +50,6 @@ public function testPersist()

$manager->persist($product);
$manager->commit();
$manager->flush();
$manager->refresh();

$repository = $manager->getRepository('AcmeTestBundle:Product');
/** @var Product[] $actualProduct */
Expand Down
39 changes: 39 additions & 0 deletions Tests/Functional/ORM/RepositoryTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -246,4 +246,43 @@ protected function getProductsArray()
{
return $this->getDataArray()['default']['product'];
}

/**
* Tests if document is being updated when persisted.
*/
public function testDocumentUpdate()
{
$manager = $this->getManager();
$repository = $manager->getRepository('AcmeTestBundle:Product');

/** @var Product $document */
$document = $repository->createDocument();

$document->setId(5);
$document->title = 'awesome';

$manager->persist($document);
$manager->commit();

// Creates document.
$document = $repository->find(5);
$this->assertEquals(
['id' => '5', 'title' => 'awesome'],
array_filter(get_object_vars($document)),
'Document should be created.'
);

$document->title = 'more awesome';

// Updates document.
$manager->persist($document);
$manager->commit();

$document = $repository->find(5);
$this->assertEquals(
['id' => '5', 'title' => 'more awesome'],
array_filter(get_object_vars($document)),
'Document should be updated.'
);
}
}