我这样做是为了映射我的文档的非注释映射。但它并没有赶上它。我知道这是旧代码,但有人知道如何正确映射它。谢谢!
还与此相关: 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 Document的values属性的持久性。
以下是PaymentDetails
的映射以及超类的映射
似乎问题是因为BaseModel的奇怪的setter / getter由PaymentDetails扩展。
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];
}
}
答案 0 :(得分:1)
我发现并修复了问题。我遇到了几个问题:
name
是mongo中的字段,而fieldName
是属性名称(issue)。 fieldName
与任何属性不匹配,则只有silently skipped(其中ORM抛出异常)。所以很难找出为什么财产没有得到保存。 (issue)。fixing the mapping之后一切正常。