I am new with Doctrine2 and need some help. I have 2 Entities:
LocationEntity and 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 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;
}
and *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();
}
If I get locations, i get ratings for location as Array, but if I want to
get Rating and Location for it, I get NULL only in getLocation().
$ratingModel = new RatingModel($this->getServiceLocator(),
$this->auth->getIdentity());
$locModel = new LocationModel($this->getServiceLocator(),
$this->auth->getIdentity());
$locations = array();
/* @var $location \Ffb\Eventus\Entity\LocationEntity */
foreach($locModel->findAll() as $location) {
/* @var $rating \Ffb\Eventus\Entity\RatingEntity */
if ($location->getRatings()->count())
var_dump($location->getRatings()->count()); ----------------- workt
$ratings = array();
/* @var $rating \Ffb\Eventus\Entity\RatingEntity */
foreach($ratingModel->findAll() as $rating) {
$rating->getLocation(); ----------------- NULL
Can somebody help?
--
You received this message because you are subscribed to the Google Groups
"doctrine-user" group.
To unsubscribe from this group and stop receiving emails from it, send an email
to [email protected].
To post to this group, send email to [email protected].
Visit this group at http://groups.google.com/group/doctrine-user.
For more options, visit https://groups.google.com/groups/opt_out.