dongwei2610 2014-06-23 08:39
浏览 39
已采纳

Doctrine ODM关联未加载

I've started working with Doctrine MongoDB ODM. I have a Document called Document which has an association originalFile to another document called File.

class Document extends AbstractDocument
{
/**
 * @var integer $id
 *
 * @MongoDB\Id
 */
protected $id;

/**
 * @var ImportSource
 *
 * @MongoDB\ReferenceOne(targetDocument="ImportSource", cascade="all", simple=true)
 */
protected $importSource;

/**
 * @var DocumentState
 *
 * @MongoDB\ReferenceOne(targetDocument="DocumentState", cascade="all", simple=true)
 */
protected $state;

/**
 * @var \DateTime $created
 *
 * @MongoDB\Date
 */
protected $created;

/**
 * @var \DateTime $modified
 *
 * @MongoDB\Date
 */
protected $modified;

/**
 * @var File $formattedFile
 *
 * @MongoDB\ReferenceOne(targetDocument="File", cascade="all")
 */
protected $formattedFile;

/**
 * @var File $originalFilename
 *
 * @MongoDB\ReferenceOne(targetDocument="File", cascade="all")
 */
protected $originalFile;

//getters, setters etc..
}

File:

class File
{
/**
 * @var string
 *
 * @MongoDB\Id
 */
protected $id;

/**
 * @var FileType
 *
 * @MongoDB\ReferenceOne(targetDocument="FileType", cascade="all", simple=true)
 */
protected $type;

/**
 * @var string
 *
 * @MongoDB\String
 */
protected $basename;

/**
 * @var \DateTime
 *
 * @MongoDB\Date
 */
protected $created;

/**
 * @var \DateTime
 *
 * @MongoDB\Date
 */
protected $deleted;

/**
 * @var \MongoGridFSFile
 *
 * @MongoDB\File
 */
protected $file;

Storing the Document works without any problems. The Document and the File-Document are stored in MongoDB. When I'm loading the Document the $originalFile property is null. I have no clue what's missing. Is the mapping wrong or is this simply a bug in Doctrine?

Edit:

This is how I'm storing the documents:

//create if not exists
if ($documentObj === null) {
    $documentObj = new Document();
    $documentObj->setCreated(new \DateTime());
    //create file
    $file = new File();

} else {
    $documentObj->setModified(new \DateTime());
    //get file
    $file = $documentObj->getOriginalFile();
}
$file->setFile($pathToFile);
//set file
$documentObj->setOriginalFile($file);
//set import source
$documentObj->setImportSource($source);
//store document
$documents[] = $this->storeDocument($documentObj, $documentFields);

//... method storeDocument fills other properties of the document and finally persits the document:
$this->manager->persist($documentObj);
$this->manager->flush();
  • 写回答

2条回答 默认 最新

  • dongyuntao2000 2014-07-03 07:36
    关注

    I have no clue why, but it's working now... I was occupied with other projects for a few days, returned to this projects, ran my unit tests again and everything worked. Only thing I've done was a composer update. Maybe a bug correlating with my setup.

    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论
查看更多回答(1条)

报告相同问题?

悬赏问题

  • ¥15 求差集那个函数有问题,有无佬可以解决
  • ¥15 【提问】基于Invest的水源涵养
  • ¥20 微信网友居然可以通过vx号找到我绑的手机号
  • ¥15 寻一个支付宝扫码远程授权登录的软件助手app
  • ¥15 解riccati方程组
  • ¥15 display:none;样式在嵌套结构中的已设置了display样式的元素上不起作用?
  • ¥15 使用rabbitMQ 消息队列作为url源进行多线程爬取时,总有几个url没有处理的问题。
  • ¥15 Ubuntu在安装序列比对软件STAR时出现报错如何解决
  • ¥50 树莓派安卓APK系统签名
  • ¥65 汇编语言除法溢出问题