【发布时间】:2012-08-10 16:17:28
【问题描述】:
所以我有一所学校,每所学校都有多个上课时间表,每个时间表都有详细信息:
school (document)
-- bell schedule (embedded document)
---- bell schedule details (embedded document)
当我克隆学校对象并打印学校时,它会在克隆中返回正确的对象。但是,当我尝试坚持学校时,它没有正确保存详细信息。我需要做些什么才能使其正常工作吗?有什么我需要设置的标志吗?
我想做的是:
$school2 = clone $school1;
$dm->persist($school2);
$dm->flush();
---- classes ----
/**
* @MongoDB\Document(collection="schools")
*/
class School
{
/**
* @MongoDB\EmbedMany
*/
protected $bell_schedules = array();
public function addBellSchedules(BellSchedule $bellSchedules)
{
$this->bell_schedules[] = $bellSchedules;
}
public function getBellSchedules()
{
return $this->bell_schedules;
}
public function setBellSchedules(\Doctrine\Common\Collections\ArrayCollection $bell_schedules)
{
$this->bell_schedules = $bell_schedules;
return $this;
}
}
/**
* @MongoDB\EmbeddedDocument
*/
class BellSchedule
{
/**
* @MongoDB\EmbedMany
*/
private $bell_schedule_details
public function getBellScheduleDetails()
{
return $this->bell_schedule_details;
}
public function setBellScheduleDetails(\Doctrine\Common\Collections\ArrayCollection $bell_schedule_details)
{
$this->bell_schedule_details = $bell_schedule_details;
return $this;
}
}
/**
* @MongoDB\EmbeddedDocument
*/
class BellScheduleDetail
{
private $period;
private $label;
}
【问题讨论】:
-
你能分享你的类映射(例如注解、XML、YML)吗?此外,如果需要转储托管对象,您可能会发现
\Doctrine\Common\Util\Debug::dump()函数很有用,因为它忽略了对内部 Doctrine 服务的引用,这些服务很容易混淆正常的var_dump()和print_r()输出。
标签: php mongodb doctrine-orm