我是Doctrine2的新手,需要一些帮助。我有两个实体: LocationEntity和RatingEntity RatingEntity
<?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。
有人能帮忙吗?
发布于 2013-12-20 14:29:30
我不认为您需要评等实体中的locationId属性,因为该列已经使用location属性进行了映射。尝试删除locationId部分,看看它是否像预期的那样工作。
https://stackoverflow.com/questions/20705051
复制相似问题