2013-08-31 4 views
0

Je cherche de l'aide pour expliquer pourquoi ma relation OneToMany en doctrine ne renvoie qu'une seule valeur. Mon modèle de données comporte trois tables. Utilisateurs, autorisation et applications. La table d'autorisation est le lien qui mappe les utilisateurs aux applications et contient également un champ de niveau d'accès pour indiquer leur niveau d'accès pour cette application.OneToMany Relations ne renvoie qu'une seule ligne

J'ai un utilisateur qui a trois entrées d'autorisation pour trois applications différentes, mais pour une raison quelconque, doctrine charge seulement 1 de ces enregistrements d'autorisation. J'ai inclus mon modèle de données complet ci-dessous. L'attribut en question est "autorisation" dans la table Webusers.

Quelqu'un sait ce que je fais mal?

class Webusers { 
/** 
* @var integer 
* 
* @ORM\Column(name="userid", type="integer", nullable=false) 
* @ORM\Id 
* @ORM\GeneratedValue(strategy="IDENTITY") 
*/ 
private $userid;  
/** 
* @var \Doctrine\Common\Collections\Collection 
* 
* @ORM\ManyToMany(targetEntity="Applications", mappedBy="userid") 
*/ 
private $applications; 

/** 
* @var \Doctrine\Common\Collections\Collection 
* 
* @ORM\OneToMany(targetEntity="Authorization", mappedBy="user") 
*/ 
private $authorization; 

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

class Authorization { 
/** 
* @var integer 
* 
* @ORM\Column(name="accesslevel", type="integer", nullable=false) 
*/ 
private $accesslevel; 

/** 
* @var integer 
* 
* @ORM\Column(name="applicationid", type="integer", nullable=false) 
* $ORM\Id 
*/ 
private $applicationid; 

/** 
* @var integer 
* 
* @ORM\Column(name="userid", type="integer", nullable=false) 
* @ORM\Id 
*/ 
private $userid; 

/** 
* @var \Webusers 
* 
* @ORM\ManyToOne(targetEntity="Webusers") 
* @ORM\JoinColumn(name="userid", referencedColumnName="userid") 
*/ 
private $user; 
} 

class Applications { 
/** 
* @var integer 
* 
* @ORM\Column(name="applicationid", type="integer", nullable=false) 
* @ORM\Id 
* @ORM\GeneratedValue(strategy="IDENTITY") 
*/ 
private $applicationid; 

/** 
* @var string 
* 
* @ORM\Column(name="name", type="string", length=50, nullable=false) 
*/ 
private $name; 
/** 
* @var \Doctrine\Common\Collections\Collection 
* 
* @ORM\ManyToMany(targetEntity="Webusers", inversedBy="applicationid") 
* @ORM\JoinTable(name="authorization", 
* joinColumns={ 
*  @ORM\JoinColumn(name="applicationid", referencedColumnName="applicationid") 
* }, 
* inverseJoinColumns={ 
*  @ORM\JoinColumn(name="userid", referencedColumnName="userid") 
* } 
*) 
*/ 
private $userid; 

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

Répondre

0

j'ai pu corriger ce problème en tant que je spécifié la relation WebUsers et application comme ManyToOne et en leur donnant la propriété @ORM \ Id car ils constituent une clé primaire composite.

Je pense que la raison principale de l'échec était que je n'avais pas d'autorisation associée aux applications.

Les points clés de mon nouveau modèle sont les suivantes:

class Webusers { 
/** 
* @var \Doctrine\Common\Collections\Collection 
* @ORM\OneToMany(targetEntity="Authorization", mappedBy="user") 
*/ 
private $authorization; 
} 

class Authorization { 
/** 
* 
* @ORM\Id 
* @ORM\ManyToOne(targetEntity="Applications") 
* @ORM\JoinColumn(name="applicationid", referencedColumnName="applicationid") 
*/ 
private $application; 

/** 
* 
* @ORM\Id 
* @ORM\ManyToOne(targetEntity="Webusers") 
* @ORM\JoinColumn(name="userid", referencedColumnName="userid") 
*/ 
private $user; 
} 

class Applications { 
/** 
* @ORM\OneToMany(targetEntity="Authorization", mappedBy="application") 
*/ 
private $authorization; 
} 
Questions connexes