2013-12-20 1 views
0

저는 Doctrine2에 익숙하며 도움이 필요합니다. 나는 2 엔티티가 : LocationEntity 및 RatingEntity을 RatingEntityDoctrine 2 Association Mapping (ManyToOne과 OneToMany)

<?php 

use Doctrine\ORM\Mapping as ORM; 

/** 
* Rating 
* 
* @ORM\Entity 
* @ORM\Table(name="`RATING`") 
*/ 
class RatingEntity { 

    /** 
    * 
    * @var int 
    * @ORM\Id 
    * @ORM\Column(name="`ID`", type="integer", nullable=false) 
    * @ORM\GeneratedValue(strategy="SEQUENCE") 
    * @ORM\SequenceGenerator(sequenceName="RATING_ID_SEQ", initialValue=1, allocationSize=1) 
    */ 
    protected $id; 

    /** 
    * 
    * @var int 
    * @ORM\Column(name="`LOCATION_ID`", type="integer") 
    */ 
    protected $locationId; 

    /** 
    * @var LocationEntity 
    * @ORM\ManyToOne(targetEntity="LocationEntity", inversedBy="ratings") 
    * @ORM\JoinColumn(name="`LOCATION_ID`", referencedColumnName="`ID`") 
    */ 
    protected $location; 

    /** 
    * @return the $location 
    */ 
    public function getLocation() { 
     return $this->location; 
    } 

    /** 
    * @param field_type $location 
    */ 
    public function setLocation($location) { 
     $this->location = $location; 
    } 

LocationEntity

<?php  

use Doctrine\ORM\Mapping as ORM; 
use Doctrine\Common\Collections\ArrayCollection; 
use Doctrine\Common\Collections\Collection; 

/** 
* Location 
* 
* @ORM\Entity 
* @ORM\Table(name="`LOCATION`") 
*/ 
class LocationEntity { 

    /** 
    * 
    * @var int 
    * @ORM\Id 
    * @ORM\Column(name="`ID`", type="integer", nullable=false) 
    * @ORM\GeneratedValue(strategy="SEQUENCE") 
    * @ORM\SequenceGenerator(sequenceName="LOCATION_ID_SEQ", initialValue=1, allocationSize=1) 
    */ 
    protected $id;    

    /** 
    * 
    * @var ArrayCollection 
    * @ORM\OneToMany(targetEntity="RatingEntity", mappedBy="location", cascade={"persist"}, fetch="LAZY") 
    */ 
    protected $ratings; 

    /** 
    * @return the $ratings 
    */ 
    public function getRatings() { 

     return $this->ratings; 
    } 

    /** 
    * @param \Doctrine\Common\Collections\ArrayCollection $ratings 
    */ 
    public function setRatings($ratings) { 

     $this->ratings = $ratings; 
    } 

    /** 
    * Never forget to initialize all your collections! 
    */ 
    public function __construct() { 
     $this->ratings = new ArrayCollection(); 
    } 

내가 위치를 얻을 경우 내가 원한다면, 내가 배열, 같은 위치에 대한 평가를 얻을 수 있지만, 그것에 대한 등급 및 위치를 가져 오려면 getLocation()에서만 NULL이 표시됩니다.

누군가 도울 수 있습니까?

답변

0

열이 이미 location 속성을 사용하여 매핑되었으므로 등급 엔티티에 locationId 속성이 필요하다고 생각하지 않습니다. locationId 섹션을 제거하고 예상대로 작동하지 않는지보십시오.

+0

이것은 이전 코드의 일부이며 필드를 객체로 변경합니다. 나는 그것을 이미 제거하려고 노력했다. 이것은 도움이되지 않습니다. – user1110233

관련 문제