doctrine / mongodb-odm version 1.0.8
我有一个文档,它使用自引用多对多的双向关系。无形中我收到错误告诉我必须设置cascade = persist。我做到了,现在我得到了一个非常奇怪的学说错误。我的文件:
use Doctrine\ODM\MongoDB\Mapping\Annotations as ODM;
/**
* @ODM\Document(collection="ledger", repositoryClass="Tng\ExampleBundle\Repository\LedgerRepository")
*/
class Ledger
{
/**
* @ODM\Id(strategy="AUTO")
*/
protected $id;
/**
* If this is a payment, this will link to the debit ledger
* @ODM\ReferenceMany(
* targetDocument="Tng\ExampleBundle\Document\Ledger",
* inversedBy="payment",
* strategy="addToSet",
* cascade={"persist"},
* simple=true
* )
*/
protected $payment_for;
/**
* If this is a debit, these are the payments and credits
* @ODM\ReferenceMany(
* targetDocument="Tng\ExampleBundle\Document\Ledger",
* mappedBy="payment_for",
* strategy="addToSet",
* cascade={"persist"},
* simple=true
* )
*/
protected $payments;
public function __construct()
{
$this->payments = new \Doctrine\Common\Collections\ArrayCollection();
$this->payment_for = new \Doctrine\Common\Collections\ArrayCollection();
}
// all standard getters/setters with:
public function addPaymentFor(\Tng\ExampleBundle\Document\Ledger $paymentFor)
{
$this->payment_for[] = $paymentFor;
$paymentFor->payments[] = $this;
}
public function removePaymentFor(\Tng\ExampleBundle\Document\Ledger $paymentFor)
{
$this->payment_for->removeElement($paymentFor);
$paymentFor->payments->removeElement($this);
}
}
现在,当我尝试保存级联记录时:
$payment->setPaymentFor($ledger);
$dm->persist($payment);
我收到以下错误:
注意:未定义的索引:$ set
堆栈跟踪
- 在vendor / doctrine / mongodb-odm / lib / Doctrine / ODM / MongoDB / Persisters / DocumentPersister.php第315行 -
- 在ErrorHandler - > handleError(' 8','未定义的索引:$ set',' / var / www / etc-mongo-tng / vendor / doctrine /mongodb-odm/lib/Doctrine/ODM/MongoDB/Persisters/DocumentPersister.php' ;,' 315',array(' data' => array(),&# 39;选项' =>数组(' upsert' => true)))
- 在vendor / doctrine / mongodb-odm / lib / Doctrine / ODM / MongoDB / Persisters / DocumentPersister.php第315行+ 在DocumentPersister - > executeUpsert(array(),array())
- in vendor / doctrine / mongodb-odm / lib / Doctrine / ODM / MongoDB / Persisters / DocumentPersister.php第296行+
- at DocumentPersister - > executeUpserts(array()) 在vendor / doctrine / mongodb-odm / lib / Doctrine / ODM / MongoDB / UnitOfWork.php第1189行+
- at UnitOfWork - > executeUpserts(object(ClassMetadata),array(' 000000005a8560de00007fc48349ed60' => object(Ledger)),array()) 在vendor / doctrine / mongodb-odm / lib / Doctrine / ODM / MongoDB / UnitOfWork.php第425行+
醇>
看起来同样的错误不会影响1.1.2分支。如果我按如下方式修补DocumentPersister.php,那一切都有效。这是一个合法的错误吗?我应该做PR吗?
private function executeUpsert(array $data, array $options)
{
// I added this line
if (empty($data)) { return; }
$options['upsert'] = true;
$criteria = array('_id' => $data['$set']['_id']);
unset($data['$set']['_id']);