Symfony FOSUser实体和FOSMessage文档之间的混合数据库SQL/No SQL模型

Symfony FOSUser实体和FOSMessage文档之间的混合数据库SQL/No SQL模型,symfony,doctrine-orm,fosuserbundle,doctrine-odm,Symfony,Doctrine Orm,Fosuserbundle,Doctrine Odm,大家好 几天以来,我一直在尝试在混合数据库SQL/无SQL模型上使用FOSUser实现FOSMessage 我尝试将FOSUSER继承的实体与FOSMessage继承的文档链接起来 我找到了一种方法来定义它们之间的所有关系: ->对于一对多关系,我在FOSUSER实体中使用Gedmo/Reference Many,在FOSMessage文档中使用Gedmo/Reference One ->对于多对多关系,我使用一个中间嵌入的文档——名为Participant——将多对多关系与线程文档结合起来。最

大家好

几天以来,我一直在尝试在混合数据库SQL/无SQL模型上使用FOSUser实现FOSMessage

我尝试将FOSUSER继承的实体与FOSMessage继承的文档链接起来

我找到了一种方法来定义它们之间的所有关系:

->对于一对多关系,我在FOSUSER实体中使用Gedmo/Reference Many,在FOSMessage文档中使用Gedmo/Reference One

->对于多对多关系,我使用一个中间嵌入的文档——名为Participant——将多对多关系与线程文档结合起来。最后,我将这个嵌入的文档与一个Gedmo/引用文档和我的FOSUSER继承实体链接起来

见下文实体和文件

我的用户实体

<?php

   namespace BeeConcept\UserBundle\Entity;

   use FOS\UserBundle\Model\User as BaseUser;
   use FOS\ElasticaBundle\Configuration\Search;
   use FOS\MessageBundle\Model\ParticipantInterface;
   use Doctrine\ORM\Mapping as ORM;
   use Gedmo\Mapping\Annotation as Gedmo;
   use Symfony\Component\Validator\Constraints as Assert;
   use BeeConcept\UserBundle\Validator\Age;
   use Symfony\Bridge\Doctrine\Validator\Constraints\UniqueEntity;

   /**
    * User
    * @ORM\Entity
    * @ORM\Table(name="User")
    * @ORM\Entity(repositoryClass="BeeConcept\UserBundle\Entity\UserRepository")
    * @Search(repositoryClass="BeeConcept\SearchBundle\Model\UserSearchRepository")
    * @UniqueEntity(fields="username", message="Le pseudonyme choisit existe déjà. Merci de vous en choisir un autre")
    */

 class User extends BaseUser implements ParticipantInterface  
 {
   /**
    * @ORM\Id
    * @ORM\Column(type="integer")
    * @ORM\GeneratedValue(strategy="AUTO")
    */
   protected $id;

    /**
    * @var string
    *
    * @ORM\Column(name="idn_id", type="string", length=255, unique=true, nullable=true)
    */

   protected $idn_id;

   /**
    * @var string
    *
    * @ORM\Column(name="facebook_id", type="string", length=255, unique=true, nullable=true)
    */

   protected $facebook_id;

   /**
    * @var string
    *
    * @ORM\Column(name="google_id", type="string", length=255, unique=true, nullable=true)
    */

   protected $google_id;

   /**
    * @ORM\OneToMany(targetEntity="BeeConcept\UserBundle\Entity\Date", mappedBy="user", cascade={"remove"})
    * @ORM\JoinColumn(nullable=true)
    */
   protected $date;

   /**
    * @ORM\OneToMany(targetEntity="BeeConcept\UserBundle\Entity\Friend", mappedBy="friendFrom")
    * @ORM\JoinColumn(nullable=true)
    */
   private $friendFrom;

   /**
    * @ORM\OneToMany(targetEntity="BeeConcept\UserBundle\Entity\Friend", mappedBy="friendTo")
    * @ORM\JoinColumn(nullable=true)
    */
   private $friendTo;

   /**
    * @ORM\ManyToMany(targetEntity="BeeConcept\JobBundle\Entity\Skill")
    * @Assert\Valid
    */
   private $skill;

/**
 * @ORM\OneToMany(targetEntity="BeeConcept\JobBundle\Entity\Note", mappedBy="note")
 * @ORM\JoinColumn(nullable=true)
 */
private $note;

/**
 * @ORM\OneToMany(targetEntity="BeeConcept\JobBundle\Entity\Experience", mappedBy="note")
 * @ORM\JoinColumn(nullable=true)
 */
private $experience;

/**
 * @ORM\Column(name="Civ", type="string")
 *
 * @Assert\NotBlank(message="Merci de sélectionner votre Civilité")
 * @Assert\Choice(choices = {"M", "MME"})
 */
protected $Civ;

/**
 * @ORM\Column(name="Prenom", type="string", length=50)
 * @Assert\NotBlank(message="Merci de renseigner votre Prénom")
 * @Assert\Length(min=0, max = 50, maxMessage="Merci d'entrer 50 caractères maximum")
 * @Assert\Regex("/(^\D+)(\w+|[-]?)/", message="Pour le Prénom, les caractères spéciaux, hormis '-', ne sont pas admis")
 */
protected $Prenom;

/**
 * @ORM\Column(name="Nom", type="string", length=50)
 * @Assert\NotBlank(message="Merci de renseigner votre Nom"))
 * @Assert\Length(min=0, max = 50, maxMessage="Merci d'entrer 50 caractères maximum")
 * @Assert\Regex("/(^\D+)(\w+|[-]?)/", message="Pour le Nom, les caractères spéciaux, hormis '-', ne sont pas admis")
 */
protected $Nom;

 /**
 * @var \Date
 *
 * @ORM\Column(name="naissance", type="date", nullable=true)
 * @Assert\Date(message="Vous n'avez pas entré votre date de naissance")
 * @Age(message = "Vous devez être majeur pour vous inscrire à ce service")
 */
protected $Naissance;   

/**
 * @ORM\Column(name="CGU", type="boolean")
 * @Assert\True(message = "Veuillez accepter les conditions générales")
 */
protected $CGU;

/**
 * @ORM\OneToOne(targetEntity="BeeConcept\UserBundle\Entity\Phone", cascade={"persist", "remove"})
 * @Assert\Valid
 */
protected $Phone;

/**
 * @ORM\ManyToOne(targetEntity="BeeConcept\UserBundle\Entity\Address", inversedBy="user")
 * @Assert\Valid
 */
protected $Address;

/**
 * @ORM\OneToOne(targetEntity="BeeConcept\UserBundle\Entity\Profil", cascade={"persist","remove"})
 * @ORM\JoinColumn(nullable=true)
 * @Assert\Valid
 */
protected $Profil;

/**
 * @ORM\OneToMany(targetEntity="BeeConcept\RucheBundle\Entity\Ruche", mappedBy="creator")
 * @Assert\Valid
 */
protected $ruche_creator;

/**
 * @ORM\ManyToMany(targetEntity="BeeConcept\RucheBundle\Entity\Ruche")
 * @Assert\Valid
 */
protected $ruche;

/**
 * @Gedmo\ReferenceMany(type="document", class="BeeConcept\CommentBundle\Document\Comment", mappedBy="author")
 */
protected $comments;

/**
 * @Gedmo\ReferenceMany(type="document", class="BeeConcept\MessageBundle\Document\Message", mappedBy="sender")
 */
protected $messages;

/**
 * @Gedmo\ReferenceMany(type="document", class="BeeConcept\MessageBundle\Document\Thread", mappedBy="createdBy")
 */
protected $threads;

/**
 * @Gedmo\ReferenceMany(type="document", class="BeeConcept\MessageBundle\Document\Participant", mappedBy="participant")
 */
protected $participants;

/**
 * @Gedmo\ReferenceMany(type="document", class="BeeConcept\MessageBundle\Document\ThreadMetadata", mappedBy="participant")
 */
protected $threadmetadatas;   

/**
 * @Gedmo\ReferenceMany(type="document", class="BeeConcept\MessageBundle\Document\MessageMetadata", mappedBy="participant")
 */
protected $messagemetadatas;

/**
 * Constructor
 */
public function __construct()
{
    parent::__construct();
    $this->ruche_creator = new \Doctrine\Common\Collections\ArrayCollection();
    $this->ruche = new \Doctrine\Common\Collections\ArrayCollection();
    $this->friendFrom = new \Doctrine\Common\Collections\ArrayCollection();
    $this->friendTo = new \Doctrine\Common\Collections\ArrayCollection();
    //$this->friends = new \Doctrine\Common\Collections\ArrayCollection( array_merge($this->friendTo->toArray(), $this->friendFrom->toArray()));
}

/**
 * Get id
 *
 * @return integer 
 */
public function getId()
{
    return $this->id;
}

/**
 * Set dateDeCreation
 *
 * @param \DateTime $dateDeCreation
 * @return User
 */
public function setDateDeCreation($dateDeCreation)
{
    $this->dateDeCreation = $dateDeCreation;

    return $this;
}

/**
 * Get dateDeCreation
 *
 * @return \DateTime 
 */
public function getDateDeCreation()
{
    return $this->dateDeCreation;
}

/**
 * Set Civ
 *
 * @param string $civ
 * @return User
 */
public function setCiv($civ)
{
    $this->Civ = $civ;

    return $this;
}

/**
 * Get Civ
 *
 * @return string 
 */
public function getCiv()
{
    return $this->Civ;
}

/**
 * Set Prenom
 *
 * @param string $prenom
 * @return User
 */
public function setPrenom($prenom)
{
    $this->Prenom = $prenom;

    return $this;
}

/**
 * Get Prenom
 *
 * @return string 
 */
public function getPrenom()
{
    return $this->Prenom;
}

/**
 * Set Nom
 *
 * @param string $nom
 * @return User
 */
public function setNom($nom)
{
    $this->Nom = $nom;

    return $this;
}

/**
 * Get Nom
 *
 * @return string 
 */
public function getNom()
{
    return $this->Nom;
}

/**
 * Set Naissance
 *
 * @param \DateTime $naissance
 * @return User
 */
public function setNaissance($naissance)
{
    $this->Naissance = $naissance;

    return $this;
}

/**
 * Get Naissance
 *
 * @return \DateTime 
 */
public function getNaissance()
{
    return $this->Naissance;
}

/**
 * Set CGU
 *
 * @param boolean $cGU
 * @return User
 */
public function setCGU($cGU)
{
    $this->CGU = $cGU;

    return $this;
}

/**
 * Get CGU
 *
 * @return boolean 
 */
public function getCGU()
{
    return $this->CGU;
}

/**
 * Set Phone
 *
 * @param \BeeConcept\UserBundle\Entity\Phone $Phone
 * @return User
 */
public function setPhone(\BeeConcept\UserBundle\Entity\Phone $Phone = null)
{
    $this->Phone = $Phone;

    return $this;
}

/**
 * Get Phone
 *
 * @return \BeeConcept\UserBundle\Entity\Phone 
 */
public function getPhone()
{
    return $this->Phone;
}

/**
 * Set Address
 *
 * @param \BeeConcept\UserBundle\Entity\Address $Address
 * @return User
 */
public function setAddress(\BeeConcept\UserBundle\Entity\Address $Address = null)
{
    $this->Address = $Address;

    return $this;
}

/**
 * Get Address
 *
 * @return \BeeConcept\UserBundle\Entity\Address 
 */
public function getAddress()
{
    return $this->Address;
}

/**
 * Add date
 *
 * @param \BeeConcept\UserBundle\Entity\Date $date
 * @return User
 */
public function addDate(\BeeConcept\UserBundle\Entity\Date $date)
{
    $this->date[] = $date;

    return $this;
}

/**
 * Remove date
 *
 * @param \BeeConcept\UserBundle\Entity\Date $date
 */
public function removeDate(\BeeConcept\UserBundle\Entity\Date $date)
{
    $this->date->removeElement($date);
}

/**
 * Get date
 *
 * @return \Doctrine\Common\Collections\Collection 
 */
public function getDate()
{
    return $this->date;
}

/**
 * Set MeetingDate
 *
 * @param \BeeConcept\UserBundle\Entity\MeetingDate $meetingdate
 * @return User
 */
public function setMeetingDate(\BeeConcept\UserBundle\Entity\MeetingDate $meetingdate = null)
{
    $this->MeetingDate = $meetingdate;

    return $this;
}

/**
 * Get MeetingDate
 *
 * @return \BeeConcept\UserBundle\Entity\MeetingDate 
 */
public function getMeetingDate()
{
    return $this->MeetingDate;
}

/**
 * Set Profil
 *
 * @param \BeeConcept\UserBundle\Entity\Profil $profil
 * @return User
 */
public function setProfil(\BeeConcept\UserBundle\Entity\Profil $profil = null)
{
    $this->Profil = $profil;

    return $this;
}

/**
 * Get Profil
 *
 * @return \BeeConcept\UserBundle\Entity\Profil 
 */
public function getProfil()
{
    return $this->Profil;
}



/**
 * Add ruche_creator
 *
 * @param \BeeConcept\RucheBundle\Entity\Ruche $rucheCreator
 * @return User
 */
public function addRucheCreator(\BeeConcept\RucheBundle\Entity\Ruche $rucheCreator)
{
    $this->ruche_creator[] = $rucheCreator;

    return $this;
}

/**
 * Remove ruche_creator
 *
 * @param \BeeConcept\RucheBundle\Entity\Ruche $rucheCreator
 */
public function removeRucheCreator(\BeeConcept\RucheBundle\Entity\Ruche $rucheCreator)
{
    $this->ruche_creator->removeElement($rucheCreator);
}

/**
 * Get ruche_creator
 *
 * @return \Doctrine\Common\Collections\Collection 
 */
public function getRucheCreator()
{
    return $this->ruche_creator;
}

/**
 * Add ruche
 *
 * @param \BeeConcept\RucheBundle\Entity\Ruche $ruche
 * @return User
 */
public function addRuche(\BeeConcept\RucheBundle\Entity\Ruche $ruche)
{
    $this->ruche[] = $ruche;

    return $this;
}

/**
 * Remove ruche
 *
 * @param \BeeConcept\RucheBundle\Entity\Ruche $ruche
 */
public function removeRuche(\BeeConcept\RucheBundle\Entity\Ruche $ruche)
{
    $this->ruche->removeElement($ruche);
}

/**
 * Get ruche
 *
 * @return \Doctrine\Common\Collections\Collection 
 */
public function getRuche()
{
    return $this->ruche;
}

/**
 * Set idn_id
 *
 * @param string $idnId
 * @return User
 */
public function setIdnId($idnId)
{
    $this->idn_id = $idnId;

    return $this;
}

/**
 * Get idn_id
 *
 * @return string 
 */
public function getIdnId()
{
    return $this->idn_id;
}

/**
 * Add friendFrom
 *
 * @param \BeeConcept\UserBundle\Entity\Friend $friendFrom
 * @return User
 */
public function addFriendFrom(\BeeConcept\UserBundle\Entity\Friend $friendFrom)
{
    $this->friendFrom[] = $friendFrom;

    return $this;
}

/**
 * Remove friendFrom
 *
 * @param \BeeConcept\UserBundle\Entity\Friend $friendFrom
 */
public function removeFriendFrom(\BeeConcept\UserBundle\Entity\Friend $friendFrom)
{
    $this->friendFrom->removeElement($friendFrom);
}

/**
 * Get friendFrom
 *
 * @return \Doctrine\Common\Collections\Collection 
 */
public function getFriendFrom()
{
    return $this->friendFrom;
}

/**
 * Add friendTo
 *
 * @param \BeeConcept\UserBundle\Entity\Friend $friendTo
 * @return User
 */
public function addFriendTo(\BeeConcept\UserBundle\Entity\Friend $friendTo)
{
    $this->friendTo[] = $friendTo;

    return $this;
}

/**
 * Remove friendTo
 *
 * @param \BeeConcept\UserBundle\Entity\Friend $friendTo
 */
public function removeFriendTo(\BeeConcept\UserBundle\Entity\Friend $friendTo)
{
    $this->friendTo->removeElement($friendTo);
}

/**
 * Get friendTo
 *
 * @return \Doctrine\Common\Collections\Collection 
 */
public function getFriendTo()
{
    return $this->friendTo;
}

 /**
 * Get friends
 *
 * @return \Doctrine\Common\Collections\Collection 
 */
public function getFriends()
{
    return new \Doctrine\Common\Collections\ArrayCollection( array_merge($this->friendTo->toArray(), $this->friendFrom->toArray()));
}

/**
 * Add skill
 *
 * @param \BeeConcept\JobBundle\Entity\Skill $skill
 *
 * @return User
 */
public function addSkill(\BeeConcept\JobBundle\Entity\Skill $skill)
{
    $this->skill[] = $skill;

    return $this;
}

/**
 * Remove skill
 *
 * @param \BeeConcept\JobBundle\Entity\Skill $skill
 */
public function removeSkill(\BeeConcept\JobBundle\Entity\Skill $skill)
{
    $this->skill->removeElement($skill);
}

/**
 * Get skill
 *
 * @return \Doctrine\Common\Collections\Collection
 */
public function getSkill()
{
    return $this->skill;
}

/**
 * Add note
 *
 * @param \BeeConcept\JobBundle\Entity\Note $note
 *
 * @return User
 */
public function addNote(\BeeConcept\JobBundle\Entity\Note $note)
{
    $this->note[] = $note;

    return $this;
}

/**
 * Remove note
 *
 * @param \BeeConcept\JobBundle\Entity\Note $note
 */
public function removeNote(\BeeConcept\JobBundle\Entity\Note $note)
{
    $this->note->removeElement($note);
}

/**
 * Get note
 *
 * @return \Doctrine\Common\Collections\Collection
 */
public function getNote()
{
    return $this->note;
}

/**
 * Add experience
 *
 * @param \BeeConcept\JobBundle\Entity\Experience $experience
 *
 * @return User
 */
public function addExperience(\BeeConcept\JobBundle\Entity\Experience $experience)
{
    $this->experience[] = $experience;

    return $this;
}

/**
 * Remove experience
 *
 * @param \BeeConcept\JobBundle\Entity\Experience $experience
 */
public function removeExperience(\BeeConcept\JobBundle\Entity\Experience $experience)
{
    $this->experience->removeElement($experience);
}

/**
 * Get experience
 *
 * @return \Doctrine\Common\Collections\Collection
 */
public function getExperience()
{
    return $this->experience;
}


/**
 * Set facebook_id
 *
 * @param string $facebookId
 *
 * @return User
 */
public function setFacebookId($facebookId)
{
    $this->facebook_id = $facebookId;

    return $this;
}

/**
 * Get facebook_id
 *
 * @return string
 */
public function getFacebookId()
{
    return $this->facebook_id;
}

/**
 * Set google_id
 *
 * @param string $googleId
 *
 * @return User
 */
public function setGoogleId($googleId)
{
    $this->google_id = $googleId;

    return $this;
}

/**
 * Get google_id
 *
 * @return string
 */
public function getGoogleId()
      {
          return $this->google_id;
      }
  }
参与者文件

 <?php

 namespace BeeConcept\MessageBundle\Document;

 use Doctrine\ODM\MongoDB\Mapping\Annotations as MongoDB;
 use Gedmo\Mapping\Annotation as Gedmo;
 use FOS\MessageBundle\Model\ParticipantInterface;

 /**
  * @MongoDB\EmbeddedDocument
  * @MongoDB\ChangeTrackingPolicy("DEFERRED_EXPLICIT")
  */

 class Participant
 {

/**
 * @Gedmo\ReferenceOne(type="entity", class="BeeConcept\UserBundle\Entity\User", inversedBy="participants", identifier="participantId")
 */
protected $participant;

/** @MongoDB\Integer */
protected $participantId;

/**
 * @return ParticipantInterface
 */
function getParticipant()
{
    return $this->participant;
}

/**
 * @param  ParticipantInterface
 * @return null
 */
function setParticipant(ParticipantInterface $participant)
{
    $this->participant = $participant;
}

public function setParticipantId()
{
    $this->participantid = $participant->getId();
}

public function getParticipantId()
{
    return $this->participantid;
}

public function getParticipantName()
{
    if (null === $this->getParticipant()) {
        return 'Anonymous';
    }

    return $this->getParticipant()->getUsername();
}

}
线程文档

 <?php
 // src/BeeConcept/MessageBundle/Document/Thread.php

 namespace BeeConcept\MessageBundle\Document;

 use Doctrine\ODM\MongoDB\Mapping\Annotations as MongoDB;
 use Gedmo\Mapping\Annotation as Gedmo;
 use FOS\MessageBundle\Document\Thread as BaseThread;
 use FOS\MessageBundle\Model\ParticipantInterface;

 /**
  * @MongoDB\Document
  * @MongoDB\ChangeTrackingPolicy("DEFERRED_EXPLICIT")
  */
 class Thread extends BaseThread
 {
/**
 * @MongoDB\Id
 */
protected $id;

/**
 * @MongoDB\ReferenceMany(targetDocument="BeeConcept\MessageBundle\Document\Message")
 */
protected $messages;

/**
 * @MongoDB\EmbedMany(targetDocument="BeeConcept\MessageBundle\Document\ThreadMetadata")
 */
protected $metadata;

/**
 * @MongoDB\EmbedMany(targetDocument="BeeConcept\MessageBundle\Document\Participant")
 */
protected $participants ;

/**
 * @Gedmo\ReferenceOne(type="entity", class="BeeConcept\UserBundle\Entity\User", inversedBy="threads", identifier="createdById")
 */
protected $createdBy;

/** @MongoDB\Integer */
protected $createdById;

public function setCreatedbyId(ParticipantInterface $createdby)
{
    $this->createdbyid = $createdby->getId();
}

public function getCreatedById()
{
    return $this->createdbyid;
}

/**
 * @param  ParticipantInterface
 * @return null
 */
public function setCreatedBy(ParticipantInterface $createdby)
{
    $this->createdby = $createdby;
}

public function getCreatedByName()
{
    if (null === $this->getCreatedBy()) {
        return 'Anonymous';
    }

    return $this->getCreatedBy()->getUsername();
}

}
看起来还可以,但我有一条新的错误消息:

在链配置的命名空间Acme\MessageBundle\Document、FOS\CommentBundle\Document、FOS\MessageBundle\Document中未找到类“Acme\UserBundle\Entity\User”


有人有线索吗?

我一直在做这项工作,并找到一种方法来定义FOSUSER Entity和FOSMessage文档之间的所有关系。我在这个主题上取得了一些进展。我已经做出了一个回答,用我遇到的新问题来说明它。但这被温和删除,没有任何解释。有人能告诉我潜台词吗。我是一个新手,只是想找到一个解决问题的方法。谢谢大家。