我需要使用 ORM 数据库实现 FOSUserBundle,并使用 MongoDB(ODM 数据库)实现 FOSMessageBundle。有可能吗?
我使用 ORM 配置 FOSUserBundle 并且可以正常工作。
我正在尝试使用文档https://github.com/FriendsOfSymfony/FOSMessageBundle/blob/master/Resources/doc/01b-odm-models.md配置 FOSMessageBundle ,问题就在这里:
/**
* @MongoDB\ReferenceOne(targetDocument="Acme\UserBundle\Document\User")
*/
protected $sender;
我没有 Acme\UserBundle\Document\User,我有 Acme\UserBundle\Entity\User 。
如果我把 Acme\UserBundle\Entity\User 不工作。
我尝试使用http://doctrine-mongodb-odm.readthedocs.org/en/latest/cookbook/blending-orm-and-mongodb-odm.html但我需要帮助。
另一种选择是在 MongoDB 中创建一个重复的用户表,但我不知道该怎么做。
感谢您的解决方案 Nawdal Serrar。
我阅读了文档并尝试了这个。不工作,你能帮帮我吗?
消息.php
/**
* @MongoDB\Document
*/
class Message extends BaseMessage{
/**
* @MongoDB\Id
*/
protected $id;
/**
* @MongoDB\EmbedMany(targetDocument="xxx\MensajeriaBundle\Document\MessageMetadata")
*/
protected $metadata;
/**
* @MongoDB\ReferenceOne(targetDocument="xxx\MensajeriaBundle\Document\Thread")
*/
protected $thread;
/**
* @Gedmo\ReferenceMany(type="entity", class="xxx\WebBundle\Entity\usuarios", mappedBy="senderMongo")
*/
protected $sender;
public function __construct()
{
$this->metadata = new \Doctrine\Common\Collections\ArrayCollection();
$this->createdAt = new \DateTime();
}
}
消息元数据.php
/**
* @ODM\EmbeddedDocument
*/
class MessageMetadata extends BaseMessageMetadata
{
/**
* @Gedmo\ReferenceMany(type="entity", class="xxx\WebBundle\Entity\usuarios", mappedBy="participantMesssageMongo")
*/
protected $participant;
}
线程类
/**
* @MongoDB\Document
*/
class Thread extends BaseThread
{
/**
* @MongoDB\Id
*/
protected $id;
/**
* @MongoDB\ReferenceMany(targetDocument="xxx\MensajeriaBundle\Document\Message")
*/
protected $messages;
/**
* @MongoDB\EmbedMany(targetDocument="xxx\MensajeriaBundle\Document\ThreadMetadata")
*/
protected $metadata;
/**
* @Gedmo\ReferenceMany(type="entity", class="xxx\WebBundle\Entity\usuarios", mappedBy="participantsMongo")
*/
protected $participants;
/**
* @Gedmo\ReferenceMany(type="entity", class="xxx\WebBundle\Entity\usuarios", mappedBy="createdByMongo")
*/
protected $createdBy;
}
线程元数据.php
/**
* @ODM\EmbeddedDocument
*/
class ThreadMetadata extends BaseThreadMetadata
{
/**
* @Gedmo\ReferenceMany(type="entity", class="xxx\WebBundle\Entity\usuarios", mappedBy="participantThreatMongo")
*/
protected $participant;
}
usuarios.php
/**
* @Gedmo\ReferenceOne(type="document", class="xxx\MensajeriaBundle\Document\Message", inversedBy="sender", identifier="senderId")
*/
private $senderMongo;
/**
* @ORM\Column(type="string", nullable=true)
*/
private $senderId;
/**
* @Gedmo\ReferenceOne(type="document", class="xxx\MensajeriaBundle\Document\MessageMetadata", inversedBy="participant", identifier="participantMessageId")
*/
private $participantMessageMongo;
/**
* @ORM\Column(type="string", nullable=true)
*/
private $participantMessageId;
/**
* @Gedmo\ReferenceOne(type="document", class="xxx\MensajeriaBundle\Document\Thread", inversedBy="participants", identifier="participantsId")
*/
private $participantsMongo;
/**
* @ORM\Column(type="string", nullable=true)
*/
private $participantsId;
/**
* @Gedmo\ReferenceOne(type="document", class="xxx\MensajeriaBundle\Document\Thread", inversedBy="createdBy", identifier="createdById")
*/
private $createdByMongo;
/**
* @ORM\Column(type="string", nullable=true)
*/
private $createdById;
/**
* @Gedmo\ReferenceOne(type="document", class="xxx\MensajeriaBundle\Document\ThreadMetadata", inversedBy="participant", identifier="participantThreadId")
*/
private $participantThreadMongo;
/**
* @ORM\Column(type="string", nullable=true)
*/
private $participantThreadId;