Doctrine / Symfony2 bidirectionnal manyToMany:一个方向失败

时间:2017-01-11 17:33:46

标签: php symfony doctrine-orm

我一直在努力解决以下问题,但无法弄明白。

我有2个entiate(Utilisateur,Residence)通过bidirectionnal manyToMany关系链接。

当我想从用户那里获得住所时,没关系

$user = $this->em->getRepository('AppBundle:Utilisateur')->findOneById(3);
$residences = $user->getUtilisateurResidences();

但是当我想让居住的用户失败时

$residence = $this->em->getRepository('AppBundle:Residence')->findOneById(3);
$negociateurs = $residence->getResidenceUtilisateurs();

使用以下错误:

Could not convert database value "" to Doctrine Type array
C:\wamp64\www\chronos-2017\src\vendor\doctrine\dbal\lib\Doctrine\DBAL\Types\ConversionException.php

有趣的是,当我为测试实体(下面的所有者和反向)执行相同的manyToMany声明时,它只是工作正常,所以它应该来自我的实体或orm yml配置文件。

拥有方

AppBundle\Entity\Owner:
type: entity
table: null
repositoryClass: AppBundle\Repository\OwnerRepository
id:
    id:
        type: integer
        id: true
        generator:
            strategy: AUTO
fields:
    nom:
        type: string
        length: 255
manyToMany:
    ownerInverses:
        targetEntity: Inverse
        cascade: {  }
        fetch: LAZY
        mappedBy: inverseOwners
        inversedBy: null
        joinTable: null
        orderBy: null
lifecycleCallbacks: {  }

反面

AppBundle\Entity\Inverse:
type: entity
table: null
repositoryClass: AppBundle\Repository\InverseRepository
id:
    id:
        type: integer
        id: true
        generator:
            strategy: AUTO
fields:
    nom:
        type: string
        length: 255
manyToMany:
    inverseOwners:
        targetEntity: Owner
        cascade: ["persist"]
        fetch: LAZY
        mappedBy: null
        orderBy: null
lifecycleCallbacks: {  }

我在测试之前更新我的entites和数据库 通过运行命令:

app/console doctrine:generate:entites AppBundle

app/console doctrine:schema:update --dump-sql (or --force)

我试图改变这段关系的拥有方,没有奏效 我为manyToMany声明尝试了另一种方式=>失败(见上图所有者和反面)

我想删除这两个实体并重新创建它们,但我的实体utilisateur用于连接和许多其他事情,如果我这样做,它会炸毁我的整个应用程序。

任何人都知道如何解决它?

谢谢: - )

以下是我的enties文件(实体+ yml配置文件)

<?php

namespace AppBundle\Entity;

use AppBundle\Entity\Residence;
use AppBundle\Entity\Role;
use FOS\UserBundle\Model\User as BaseUser;
use FR3D\LdapBundle\Model\LdapUserInterface as LdapUserInterface;

class Utilisateur extends BaseUser implements LdapUserInterface
{
    protected $id;

/**
 * @var string
 */
protected $dn;

/**
 * @var string
 */
private $login;

/**
 * @var string
 */
private $nom;

/**
 * @var string
 */
private $prenom;

/**
 * @var string
 */
private $telephone;

/**
 * @var string
 */
private $image;

/**
 * @var boolean
 */
private $indActif;

/**
 * @var boolean
 */
private $indRepartitionAleatoire;

/**
 * @var boolean
 */
private $indArchive;

/**
 * @var Role
 */
private $role;


/**
 * Set login
 *
 * @param string $login
 *
 * @return Utilisateur
 */
public function setLogin($login)
{
    $this->login = $login;

    return $this;
}

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

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

    return $this;
}

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

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

    return $this;
}

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

/**
 * Set telephone
 *
 * @param string $telephone
 *
 * @return Utilisateur
 */
public function setTelephone($telephone)
{
    $this->telephone = $telephone;

    return $this;
}

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

/**
 * Set image
 *
 * @param string $image
 *
 * @return Utilisateur
 */
public function setImage($image)
{
    $this->image = $image;

    return $this;
}

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

/**
 * Set indActif
 *
 * @param boolean $indActif
 *
 * @return Utilisateur
 */
public function setIndActif($indActif)
{
    $this->indActif = $indActif;

    return $this;
}

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

/**
 * Set indRepartitionAleatoire
 *
 * @param boolean $indRepartitionAleatoire
 *
 * @return Utilisateur
 */
public function setIndRepartitionAleatoire($indRepartitionAleatoire)
{
    $this->indRepartitionAleatoire = $indRepartitionAleatoire;

    return $this;
}

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

/**
 * Set indArchive
 *
 * @param boolean $indArchive
 *
 * @return Utilisateur
 */
public function setIndArchive($indArchive)
{
    $this->indArchive = $indArchive;

    return $this;
}

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

/**
 * Set role
 *
 * @param Role $role
 *
 * @return Utilisateur
 */
public function setRole(Role $role = null)
{
    $this->role = $role;

    return $this;
}

/**
 * Get role
 *
 * @return Role
 */
public function getRole()
{
    return $this->role;
}

public function setDn($dn)
{
    $this->dn = $dn;
}

public function getDn()
{
    return $this->dn;
}

/**
 * @var \Doctrine\Common\Collections\Collection
 */
private $residence_remplacants;


/**
 * Add residenceRemplacant
 *
 * @param \AppBundle\Entity\Utilisateur $residenceRemplacant
 *
 * @return Utilisateur
 */
public function addResidenceRemplacant(Utilisateur $residenceRemplacant)
{
    $this->residence_remplacants[] = $residenceRemplacant;

    return $this;
}

/**
 * Remove residenceRemplacant
 *
 * @param \AppBundle\Entity\Utilisateur $residenceRemplacant
 */
public function removeResidenceRemplacant(Utilisateur $residenceRemplacant)
{
    $this->residence_remplacants->removeElement($residenceRemplacant);
}

/**
 * Get residenceRemplacants
 *
 * @return \Doctrine\Common\Collections\Collection
 */
public function getResidenceRemplacants()
{
    return $this->residence_remplacants;
}
/**
 * @var \Doctrine\Common\Collections\Collection
 */
private $utilisateurResidences;


/**
 * Add utilisateurResidence
 *
 * @param \AppBundle\Entity\Residence $utilisateurResidence
 *
 * @return Utilisateur
 */
public function addUtilisateurResidence(\AppBundle\Entity\Residence $utilisateurResidence)
{
    $this->utilisateurResidences[] = $utilisateurResidence;

    return $this;
}

/**
 * Remove utilisateurResidence
 *
 * @param \AppBundle\Entity\Residence $utilisateurResidence
 */
public function removeUtilisateurResidence(\AppBundle\Entity\Residence $utilisateurResidence)
{
    $this->utilisateurResidences->removeElement($utilisateurResidence);
}

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

}

<?php

namespace AppBundle\Entity;
use AppBundle\Entity\Utilisateur;


/**
 * Residence
 *
 */
class Residence
{
    /**
     * @var integer
     */
    private $id;

/**
 * @var string
 */
private $codeImmeuble;

/**
 * @var string
 */
private $nom;

/**
 * @var string
 */
private $adresse;

/**
 * @var string
 */
private $cp;

/**
 * @var string
 */
private $ville;

/**
 * @var string
 */
private $tel;

/**
 * @var string
 */
private $email;

/**
 * @var integer
 */
private $hermesId;

/**
 * @var boolean
 */
private $nbMoisDepotGarantie;

/**
 * @var float
 */
private $mntKitNuit;

/**
 * @var boolean
 */
private $termePaiementLoyerProp = '1';

/**
 * @var boolean
 */
private $periodicitePaiementLoyer = '3';

/**
 * @var boolean
 */
private $indArchive = false;

/**
 * @var Utilisateur
 */
private $responsable;

/**
 * @var Utilisateur
 */
private $gestionnaire;

/**
 * @var \AppBundle\Entity\SecteurResidence
 */
private $secteur;

/**
 * @var \Doctrine\Common\Collections\Collection
 */
private $dossierClient;

/**
 * Constructor
 */
public function __construct()
{
    $this->dossierClient = new \Doctrine\Common\Collections\ArrayCollection();
    $this->negociateurs = new \Doctrine\Common\Collections\ArrayCollection();
}

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

/**
 * Set codeImmeuble
 *
 * @param string $codeImmeuble
 *
 * @return Residence
 */
public function setCodeImmeuble($codeImmeuble)
{
    $this->codeImmeuble = $codeImmeuble;

    return $this;
}

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

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

    return $this;
}

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

/**
 * Set adresse
 *
 * @param string $adresse
 *
 * @return Residence
 */
public function setAdresse($adresse)
{
    $this->adresse = $adresse;

    return $this;
}

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

/**
 * Set cp
 *
 * @param string $cp
 *
 * @return Residence
 */
public function setCp($cp)
{
    $this->cp = $cp;

    return $this;
}

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

/**
 * Set ville
 *
 * @param string $ville
 *
 * @return Residence
 */
public function setVille($ville)
{
    $this->ville = $ville;

    return $this;
}

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

/**
 * @return string
 */
public function getTel()
{
    return $this->tel;
}

/**
 * @param string $tel
 */
public function setTel($tel)
{
    $this->tel = $tel;
}


/**
 * Set email
 *
 * @param string $email
 *
 * @return Residence
 */
public function setEmail($email)
{
    $this->email = $email;

    return $this;
}

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

/**
 * Set commentaire
 *
 * @param string $commentaire
 *
 * @return Residence
 */
public function setCommentaire($commentaire)
{
    $this->commentaire = $commentaire;

    return $this;
}

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

/**
 * Set hermesId
 *
 * @param integer $hermesId
 *
 * @return Residence
 */
public function setHermesId($hermesId)
{
    $this->hermesId = $hermesId;

    return $this;
}

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

/**
 * Set nbMoisDepotGarantie
 *
 * @param boolean $nbMoisDepotGarantie
 *
 * @return Residence
 */
public function setNbMoisDepotGarantie($nbMoisDepotGarantie)
{
    $this->nbMoisDepotGarantie = $nbMoisDepotGarantie;

    return $this;
}

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

/**
 * Set mntKitNuit
 *
 * @param float $mntKitNuit
 *
 * @return Residence
 */
public function setMntKitNuit($mntKitNuit)
{
    $this->mntKitNuit = $mntKitNuit;

    return $this;
}

/**
 * Get mntKitNuit
 *
 * @return float
 */
public function getMntKitNuit()
{
    return $this->mntKitNuit;
}


/**
 * Set termePaiementLoyerProp
 *
 * @param smallint $termePaiementLoyerProp
 *
 * @return Residence
 */
public function setTermePaiementLoyerProp($termePaiementLoyerProp)
{
    $this->termePaiementLoyerProp = $termePaiementLoyerProp;

    return $this;
}

/**
 * Get termePaiementLoyerProp
 *
 * @return smallint
 */
public function getTermePaiementLoyerProp()
{
    return $this->termePaiementLoyerProp;
}

/**
 * Set periodicitePaiementLoyer
 *
 * @param smallint $periodicitePaiementLoyer
 *
 * @return Residence
 */
public function setPeriodicitePaiementLoyer($periodicitePaiementLoyer)
{
    $this->periodicitePaiementLoyer = $periodicitePaiementLoyer;

    return $this;
}

/**
 * Get periodicitePaiementLoyer
 *
 * @return smallint
 */
public function getPeriodicitePaiementLoyer()
{
    return $this->periodicitePaiementLoyer;
}

/**
 * Set indArchive
 *
 * @param boolean $indArchive
 *
 * @return Residence
 */
public function setIndArchive($indArchive)
{
    $this->indArchive = $indArchive;

    return $this;
}

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

/**
 * Set responsable
 *
 * @param Utilisateur $responsable
 *
 * @return Residence
 */
public function setResponsable(Utilisateur $responsable = null)
{
    $this->responsable = $responsable;

    return $this;
}

/**
 * Get responsable
 *
 * @return Utilisateur
 */
public function getResponsable()
{
    return $this->responsable;
}

/**
 * Set gestionnaire
 *
 * @param Utilisateur $gestionnaire
 *
 * @return Residence
 */
public function setGestionnaire(Utilisateur $gestionnaire = null)
{
    $this->gestionnaire = $gestionnaire;

    return $this;
}

/**
 * Get gestionnaire
 *
 * @return Utilisateur
 */
public function getGestionnaire()
{
    return $this->gestionnaire;
}

/**
 * Set secteur
 *
 * @param \AppBundle\Entity\SecteurResidence $secteur
 *
 * @return Residence
 */
public function setSecteur(\AppBundle\Entity\SecteurResidence $secteur = null)
{
    $this->secteur = $secteur;

    return $this;
}

/**
 * Get secteur
 *
 * @return \AppBundle\Entity\SecteurResidence
 */
public function getSecteur()
{
    return $this->secteur;
}

/**
 * Add dossierClient
 *
 * @param \AppBundle\Entity\DossierClient $dossierClient
 *
 * @return Residence
 */
public function addDossierClient(\AppBundle\Entity\DossierClient $dossierClient)
{
    $this->dossierClient[] = $dossierClient;

    return $this;
}

/**
 * Remove dossierClient
 *
 * @param \AppBundle\Entity\DossierClient $dossierClient
 */
public function removeDossierClient(\AppBundle\Entity\DossierClient $dossierClient)
{
    $this->dossierClient->removeElement($dossierClient);
}

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

/**
 * Add utilisateur
 *
 * @param Utilisateur $utilisateur
 *
 * @return Residence
 */

/**
 * @var string
 */
private $adresseComplement;


/**
 * Set adresseComplement
 *
 * @param string $adresseComplement
 *
 * @return Residence
 */
public function setAdresseComplement($adresseComplement)
{
    $this->adresseComplement = $adresseComplement;

    return $this;
}

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

/**
 * @var \Doctrine\Common\Collections\Collection
 */
private $remplacants;


/**
 * Add remplacant
 *
 * @param Utilisateur $remplacant
 *
 * @return Residence
 */
public function addRemplacant(Utilisateur $remplacant)
{
    $this->remplacants[] = $remplacant;

    return $this;
}

/**
 * Remove remplacant
 *
 * @param Utilisateur $remplacant
 */
public function removeRemplacant(Utilisateur $remplacant)
{
    $this->remplacants->removeElement($remplacant);
}

/**
 * Get remplacants
 *
 * @return \Doctrine\Common\Collections\Collection
 */
public function getRemplacants()
{
    return $this->remplacants;
}
/**
 * @var \Doctrine\Common\Collections\Collection
 */
private $residenceUtilisateurs;


/**
 * Add residenceUtilisateur
 *
 * @param \AppBundle\Entity\Utilisateur $residenceUtilisateur
 *
 * @return Residence
 */
public function addResidenceUtilisateur(\AppBundle\Entity\Utilisateur $residenceUtilisateur)
{
    $this->residenceUtilisateurs[] = $residenceUtilisateur;

    return $this;
}

/**
 * Remove residenceUtilisateur
 *
 * @param \AppBundle\Entity\Utilisateur $residenceUtilisateur
 */
public function removeResidenceUtilisateur(\AppBundle\Entity\Utilisateur $residenceUtilisateur)
{
    $this->residenceUtilisateurs->removeElement($residenceUtilisateur);
}

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

}

AppBundle\Entity\Utilisateur:
type: entity
repositoryClass: AppBundle\Repository\UtilisateurRepository
table: utilisateur
indexes:
    fk_utilisateur_roler_id_idx:
        columns:
            - role_id
uniqueConstraints:
    UNIQ_1D1C63B392FC23A8:
        columns:
            - username_canonical
    UNIQ_1D1C63B3A0D96FBF:
        columns:
            - email_canonical
    UNIQ_1D1C63B3C05FB297:
        columns:
            - confirmation_token
id:
    id:
        type: integer
        nullable: false
        options:
            unsigned: false
        id: true
        generator:
            strategy: IDENTITY
fields:
    nom:
        type: string
        nullable: false
        length: 255
        options:
            fixed: false
    prenom:
        type: string
        nullable: false
        length: 255
        options:
            fixed: false
    telephone:
        type: string
        nullable: true
        length: 50
        options:
            fixed: false
    image:
        type: string
        nullable: true
        length: 255
        options:
            fixed: false
    indRepartitionAleatoire:
        type: boolean
        nullable: true
        column: ind_repartition_aleatoire
    indArchive:
        type: boolean
        nullable: true
        column: ind_archive
    dn:
        type: string
        nullable: false
        length: 255
        options:
            fixed: false
manyToOne:
    role:
        targetEntity: Role
        cascade: {  }
        fetch: LAZY
        mappedBy: null
        inversedBy: null
        joinColumns:
            role_id:
                referencedColumnName: id
        orphanRemoval: false
manyToMany:
    residence_remplacants:
        targetEntity: Residence
        mappedBy: remplacants
    utilisateurResidences:
        targetEntity: Residence
        mappedBy: residenceUtilisateurs
lifecycleCallbacks: {  }


AppBundle\Entity\Residence:
type: entity
repositoryClass: AppBundle\Repository\ResidenceRepository
table: residence
uniqueConstraints:
        slug:
            columns:
                - code_immeuble
indexes:
    fk_immeuble_resp_id_idx:
        columns:
            - responsable_id
    fk_immeuble_resp_administratif_id_idx:
        columns:
            - gestionnaire_id
    fk_residence_ville_id_idx:
        columns:
            - secteur_id
id:
    id:
        type: integer
        nullable: false
        options:
            unsigned: false
        id: true
        generator:
            strategy: IDENTITY
fields:
    codeImmeuble:
        type: string
        nullable: false
        length: 2
        options:
            fixed: false
        column: code_immeuble
    nom:
        type: string
        nullable: false
        length: 255
        options:
            fixed: false
    adresse:
        type: string
        nullable: true
        length: 255
        options:
            fixed: false
    adresseComplement:
        type: string
        nullable: true
        length: 255
        options:
            fixed: false
        column: adresse_complement
    cp:
        type: string
        nullable: true
        length: 5
        options:
            fixed: false
    ville:
        type: string
        nullable: true
        length: 255
        options:
            fixed: false
    tel:
        type: string
        nullable: true
        length: 50
        options:
            fixed: false
        column: tel
    email:
        type: string
        nullable: true
        length: 255
        options:
            fixed: false
    commentaire:
        type: text
        nullable: true
        length: 65535
        options:
            fixed: false
    slug:
        type: string
        nullable: true
        length: 64
        options:
            fixed: false
    image:
        type: string
        nullable: true
        length: 255
        options:
            fixed: false
    dateOuverture:
        type: date
        nullable: true
        column: date_ouverture
    dateLivraison:
        type: date
        nullable: true
        column: date_livraison
    hermesId:
        type: integer
        nullable: true
        options:
            unsigned: false
        column: hermes_id
    nbMoisDepotGarantie:
        type: smallint
        nullable: true
        column: nb_mois_depot_garantie
    mntKitNuit:
        type: float
        nullable: true
        precision: 10
        scale: 0
        column: mnt_kit_nuit
    termePaiementLoyerProp:
        type: smallint
        nullable: true
        options:
            comment: '1 : échu, 2 : a echoir'
            default: '1'
        column: terme_paiement_loyer_prop
    periodicitePaiementLoyer:
        type: smallint
        nullable: true
        options:
            default: '3'
        column: periodicite_paiement_loyer
    indArchive:
        type: boolean
        nullable: false
        options:
            default: false
        column: ind_archive
manyToOne:
    gestionnaire:
        targetEntity: Utilisateur
        cascade: {  }
        fetch: LAZY
        mappedBy: null
        inversedBy: null
        joinColumns:
            gestionnaire_id:
                referencedColumnName: id
        orphanRemoval: false
    responsable:
        targetEntity: Utilisateur
        cascade: {  }
        fetch: LAZY
        mappedBy: null
        inversedBy: null
        joinColumns:
            responsable_id:
                referencedColumnName: id
        orphanRemoval: false
    secteur:
        targetEntity: SecteurResidence
        cascade: {  }
        fetch: LAZY
        mappedBy: null
        inversedBy: null
        joinColumns:
            secteur_id:
                referencedColumnName: id
        orphanRemoval: false
manyToMany:
    dossierClient:
        targetEntity: DossierClient
        mappedBy: residence

    residenceUtilisateurs:
        targetEntity: Utilisateur
        inversedBy: utilisateurResidences
        joinTable:
            name: residence_utilisateurs
            joinColumns:
                residence_id:
                    referencedColumnName: id
            inverseJoinColumns:
                utilisateur_id:
                    referencedColumnName: id

    remplacants:
        targetEntity: Utilisateur
        inversedBy: residence_remplacants
        joinTable:
            name: residence_remplacant
            joinColumns:
                -
                    name: residence_id
                    referencedColumnName: id
            inverseJoinColumns:
                -
                    name: utilisateur_id
                    referencedColumnName: id
lifecycleCallbacks: {  }

0 个答案:

没有答案
相关问题