0

I need implement FOSUserBundle using ORM database and FOSMessageBundle using MongoDB (ODM database). Is it posible?

I configure FOSUserBundle using ORM and works.

I am triying to configure FOSMessageBundle using the documentation https://github.com/FriendsOfSymfony/FOSMessageBundle/blob/master/Resources/doc/01b-odm-models.md the problem it is here:

/**
 * @MongoDB\ReferenceOne(targetDocument="Acme\UserBundle\Document\User")
 */
protected $sender;

I don´t have Acme\UserBundle\Document\User, I have Acme\UserBundle\Entity\User .

If I put Acme\UserBundle\Entity\User don´t work.

I try to use http://doctrine-mongodb-odm.readthedocs.org/en/latest/cookbook/blending-orm-and-mongodb-odm.html but I need help.

Another option it is create a duplicate User table in MongoDB but I don't know how I can do this.

Thanks for your solution Nawdal Serrar.

I read the documentation and try this. Don`t work, can you help me please?

Message.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();
    }

}

MessageMetadata.php

/**
 * @ODM\EmbeddedDocument
 */
class MessageMetadata extends BaseMessageMetadata
{
    /**
     * @Gedmo\ReferenceMany(type="entity", class="xxx\WebBundle\Entity\usuarios", mappedBy="participantMesssageMongo")
     */
    protected $participant;



}

Thread.class

/**
 * @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;

}

ThreadMetadata.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;

1 Answers1

0

This is what you need, you can reference relationships between ODM and ORM entities https://github.com/Atlantic18/DoctrineExtensions/blob/master/doc/references.md

Nawfal Serrar
  • 2,213
  • 1
  • 14
  • 22