在我的项目中,我需要在 orm 和 odm 之间共享对象。我有一个实体“Variation”和一个文档“Tracking”。一种变体可以容纳许多跟踪事件。我试图通过使用 stofdoctrineextensionbundle 的 symfony 2.3 的理论扩展引用来解决它,但无论我做什么它都行不通。也许你们中的某个人有一个想法。
跟踪文件:(注意 $variation )
namespace Anchorbrands\Bundle\LandingpageBundle\Document;
use Anchorbrands\Bundle\LandingpageBundle\AnchorbrandsLandingpageBundle;
use Gedmo\Mapping\Annotation as Gedmo;
use Doctrine\ODM\MongoDB\Mapping\Annotations as ODM;
/**
* @ODM\Document(collection="landingpage_tracking")
*/
class Tracking {
/**
* @Gedmo\ReferenceOne(type="entity", class="Anchorbrands\Bundle\LandingpageBundle\Entity\Variation", inversedBy="trackingEvents", identifier="variationId")
*/
protected $variation;
protected $variationId;
public function setVariationId($variationId)
{
$this->variationId = $variationId;
}
public function getVariationId()
{
return $this->variationId;
}
变体实体(注意 $trackingEvents )
/**
* Variation
*
* @ORM\Table(name="landingpage_variation")
* @ORM\Entity
*/
class Variation
{
/**
* @Gedmo\ReferenceMany(type="document", class="Anchorbrands\Bundle\LandingpageBundle\Document\Tracking", mappedBy="variation")
*/
protected $trackingEvents;
public function getTrackingEvents()
{
return $this->trackingEvents;
}
public function setTrackingEvents(Collection $trackingEvents)
{
$this->trackingEvents = $trackingEvents;
}