学说/mongodb-odm 版本 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
堆栈跟踪
- 在第 315 行的 vendor/doctrine/mongodb-odm/lib/Doctrine/ODM/MongoDB/Persisters/DocumentPersister.php -
- 在 ErrorHandler ->handleError ('8', '未定义索引: $set', '/var/www/etc-mongo-tng/vendor/doctrine/mongodb-odm/lib/Doctrine/ODM/MongoDB/Persisters/DocumentPersister. php', '315', 数组('data' => array(), 'options' => array('upsert' => true)))
- 在 vendor/doctrine/mongodb-odm/lib/Doctrine/ODM/MongoDB/Persisters/DocumentPersister.php 在第 315 行 + 在 DocumentPersister ->executeUpsert (array(), array())
- 在 vendor/doctrine/mongodb-odm/lib/Doctrine/ODM/MongoDB/Persisters/DocumentPersister.php 第 296 行 +
- 在第 1189 行的 vendor/doctrine/mongodb-odm/lib/Doctrine/ODM/MongoDB/UnitOfWork.php 中的 DocumentPersister ->executeUpserts (array()) +
- 在 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']);