9

我这样做是为了映射我的文档的非注释映射。但它没有赶上它。我知道这是旧代码,但有人知道如何正确映射它。谢谢!

相关公关 = https://github.com/Payum/PaypalExpressCheckoutNvp/pull/12/files#diff-fcfa75e424ccb89d62449aba21f9db31R49

也与此相关: https ://groups.google.com/forum/#!topic/doctrine-user/MdIoOMWA7F4 https://github.com/doctrine/mongodb-odm/issues/421 https://github。 com/doctrine/mongodb-odm/issues/453

<?php

abstract class MongoTest extends BaseMongoTest
{
/**
 * {@inheritDoc}
 */
protected function getMetadataDriverImpl()
{
    $rootDir = realpath(__DIR__.'/../../../../../../../../../');
    if (false === $rootDir || false === is_dir($rootDir.'/src/Payum')) {
        throw new \RuntimeException('Cannot guess Payum root dir.');
    }

$driver = new MappingDriverChain;
    $xmlDriver = new XmlDriver(
        new SymfonyFileLocator(
            array(
                $rootDir.'/src/Payum/Paypal/ExpressCheckout/Nvp/Bridge/Doctrine/Resources/mapping'
                => 'Payum\Paypal\ExpressCheckout\Nvp\Bridge\Doctrine\Document',
                $rootDir.'/examples/Payum/Paypal/ExpressCheckout/Nvp/Examples/Resources/mapping'
                => 'Payum\Paypal\ExpressCheckout\Nvp\Examples\Document'
            ),
            '.mongodb.xml'
        ),
        '.mongodb.xml'
    );
    $driver->addDriver($xmlDriver, 'Payum\Paypal\ExpressCheckout\Nvp\Examples\Document');
    $driver->addDriver($xmlDriver, 'Payum\Paypal\ExpressCheckout\Nvp\Bridge\Doctrine\Document');


    return $driver;
}

我收到 2 次测试失败的错误,因为示例文件夹下 PaymentDetail 文档的值属性没有持久性。

这是 PaymentDetails 的映射

https://github.com/cordoval/PaypalExpressCheckoutNvp/blob/mongo-tests/src/Payum/Paypal/ExpressCheckout/Nvp/Bridge/Doctrine/Resources/mapping/PaymentDetails.mongodb.xml?pr=%2FPayum%2FPaypalExpressCheckoutNvp%2Fpull %2F12

和超类的映射

https://github.com/cordoval/PaypalExpressCheckoutNvp/blob/mongo-tests/examples/Payum/Paypal/ExpressCheckout/Nvp/Examples/Resources/mapping/PaymentDetails.mongodb.xml?pr=%2FPayum%2FPaypalExpressCheckoutNvp%2Fpull%2F12

似乎问题是由于由 PaymentDetails 扩展的 BaseModel 的怪异 setter/getter。

protected $paymentrequest_nnn_amt = array();

    public function getPaymentrequestAmt($n = null)
    {
        return $this->get('paymentrequest_nnn_amt', $n);
    }

    public function setPaymentrequestAmt($n, $value)
    {
        $this->set('paymentrequest_nnn_amt', $value, $n);
    }

上面是来自中间基类,下面是来自基类

/**
 * @param string $property
 * @param bool   $n
 * @param bool   $m
 *
 * @return mixed
 */
protected function get($property, $n = false, $m = false)
{
    $currentValue = $this->$property;
    if (false !== $n && false !== $m) {
        if (null === $n && null === $m) {
            return $currentValue;
        }
        if (array_key_exists($n, $currentValue) && array_key_exists($m,$currentValue[$n]){
            return $currentValue[$n][$m];
        }
    }
    if (null === $n) {
        return $currentValue;
    }
    if (array_key_exists($n, $currentValue)) {
        return $currentValue[$n];
    }
}
4

1 回答 1

1

我发现并解决了这个问题。我遇到了几个问题:

  • 首先,在长时间使用 ORM 之后,我很困惑,这name是 mongo 中的一个字段,fieldName是一个属性名称(issue)。
  • 其次,如果fieldName不匹配任何属性,它就会被静默地跳过(ORM 抛出异常)。所以很难找出为什么该属性没有被保存。(问题)。

修复映射后一切正常。

于 2013-10-11T08:17:22.033 回答