Doctrine MongoDB ODM 加载参考文档
我的详细情况是,iv'e 得到了一份用户文档:
/** @Document(collection="user") */
class User
{
/** @Id */
private $id;
/** @ReferenceMany(targetDocument="Pet") */
private $pet;
public function getPet()
{
return $this->pet;
}
}
并且 iv'e 得到了一份宠物文档:
/** @Document(collection="pet") */
class Pet
{
/** @Id */
private $id;
/** @ReferenceMany(targetDocument="User") */
private $user;
public function getUser()
{
return $this->user;
}
}
多对多关联。如果我为现有文档调用以下代码...
$result = $this->_dbContainer->getDocumentManager()->getRepository('User')->findBy(array('id' => => 'XZTZHJ323LKFHGJKLHGFGHJK'));
print_r($result->toArray());
...它将以无限循环结束。错误消息:
PHP Fatal error: Allowed memory size of 134217728 bytes exhausted (tried to allocate 112721921 bytes) in ...
如果我执行以下代码:
var_dump($result->count());
结果是一个/它存在(一切正常)。 $result->current() 的 var_dump 为 NULL。 getMongoData 方法返回以下数据(这是正确的):
Array ( [0] => Array ( [$ref] => example [$id] => MongoId Object ( [$id] => 4ddac7667294c79e17000002 ) [$db] => test ) )
如果我执行以下代码:
var_dump($result->current());
结果是布尔值(false)。
有什么想法吗?
my szenario in detail, iv'e got one User Document:
/** @Document(collection="user") */
class User
{
/** @Id */
private $id;
/** @ReferenceMany(targetDocument="Pet") */
private $pet;
public function getPet()
{
return $this->pet;
}
}
and iv'e got one Pet document:
/** @Document(collection="pet") */
class Pet
{
/** @Id */
private $id;
/** @ReferenceMany(targetDocument="User") */
private $user;
public function getUser()
{
return $this->user;
}
}
A many to many correlation. If i call the following code for an existing document...
$result = $this->_dbContainer->getDocumentManager()->getRepository('User')->findBy(array('id' => => 'XZTZHJ323LKFHGJKLHGFGHJK'));
print_r($result->toArray());
...it ends in an endless loop. Error message:
PHP Fatal error: Allowed memory size of 134217728 bytes exhausted (tried to allocate 112721921 bytes) in ...
If i execute the following code:
var_dump($result->count());
The result ist one / it exist (everything ok). A var_dump of $result->current() is NULL. The method getMongoData returns the following data (which is correct):
Array ( [0] => Array ( [$ref] => example [$id] => MongoId Object ( [$id] => 4ddac7667294c79e17000002 ) [$db] => test ) )
If i execute the following code:
var_dump($result->current());
The result is boolean (false).
Any ideas?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(3)
尝试重新生成水化器类。
try regenerating hydrator classes.
如果您的模型看起来像这样,
您应该能够使用
“不要尝试
var_dump()
”或print_r()
模型代理对象来检索引用的模型。它们包含许多递归引用,尝试将它们呈现为输出时,您将耗尽可用内存。Provided your model looks something like this
You should be able to retrieve the referenced models using
Do not attempt to
var_dump()
orprint_r()
the model proxy objects. These contain many recursive references and you will exhaust your available memory attempting to render them as output.从引用集合中获取单个对象的解决方案:
最大的学习(感谢@Phil):
此致,
斯蒂芬
Solution to get a single object from a referenced collection:
Biggest learning (thanks to @Phil):
Best regards,
Stephan