2013-08-31 61 views
0

我在寻找一些帮助,为什么我在学说中的OneToMany关系只返回一个值。我的数据模型有三个表。用户,授权和应用程序。授权表是将用户映射到应用程序的粘合剂,并且还包含访问级别字段以指示其对该应用程序的访问级别。OneToMany Relationship Only Only 1 Row

我有一个用户在三个不同的应用程序的授权中有三个条目,但由于某种原因,原则只加载了这些授权记录中的一个。我已经在下面包含了我的完整数据模型。有问题的属性是Webusers表中的“授权”。

任何人都知道我在做什么错了?

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

回答

0

我能够确保我指定了该网站用户和应用关系,多对一,并给他们的@ORM \ Id属性,因为它们构成了一个复合主键来解决这个问题。

我认为这是失败的主要原因是因为我没有将授权与应用程序关联。

我的新模式的关键点如下:

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; 
}