When I try to get data like this, I got missing data:
$this->em->getRepository("PollBundle:Poll")->findAll();
Here are the results that I got: http://i.imgur.com/f0M54og.png
The system is getting poll's data however nothing to show about frequency as you can see. What's wrong?
PollFrequency Entity is like that as following:
namespace PollBundle\Entity;
use Doctrine\ORM\Mapping as ORM;
use Doctrine\Common\Collections\ArrayCollection;
/**
* PollFrequency
*
* #ORM\Table(name="poll_frequency")
* #ORM\Entity
*/
class PollFrequency
{
/**
* #var integer
*
* #ORM\Column(name="id", type="integer")
* #ORM\Id
* #ORM\GeneratedValue(strategy="AUTO")
*/
private $id;
/**
* #ORM\OneToMany(targetEntity="Poll", mappedBy="poll_frequency")
*/
private $polls;
/**
* #var string
* #ORM\Column(name="frequency", type="string")
*/
private $frequency;
/**
* #var string
* #ORM\Column(name="description", type="string")
*/
private $description;
public function __construct()
{
$this->polls = new ArrayCollection();
}
/**
* Get id
*
* #return integer
*/
public function getId()
{
return $this->id;
}
/**
* Set frequency
*
* #param string $frequency
* #return PollFrequency
*/
public function setFrequency($frequency)
{
$this->frequency = $frequency;
return $this;
}
/**
* Get frequency
*
* #return string
*/
public function getFrequency()
{
return $this->frequency;
}
/**
* Set description
*
* #param string $description
* #return PollFrequency
*/
public function setDescription($description)
{
$this->description = $description;
return $this;
}
/**
* Get description
*
* #return string
*/
public function getDescription()
{
return $this->description;
}
/**
* Add polls
*
* #param \PollBundle\Entity\Poll $polls
* #return PollFrequency
*/
public function addPoll(\PollBundle\Entity\Poll $polls)
{
$this->polls[] = $polls;
return $this;
}
/**
* Remove polls
*
* #param \PollBundle\Entity\Poll $polls
*/
public function removePoll(\PollBundle\Entity\Poll $polls)
{
$this->polls->removeElement($polls);
}
/**
* Get polls
*
* #return \Doctrine\Common\Collections\Collection
*/
public function getPolls()
{
return $this->polls;
}
}
Poll Entity is also here as following:
<?php
namespace PollBundle\Entity;
use Doctrine\ORM\Mapping as ORM;
/**
* Poll
*
* #ORM\Table(name="poll")
* #ORM\Entity
*/
class Poll
{
/**
* #var integer
*
* #ORM\Column(name="id", type="integer")
* #ORM\Id
* #ORM\GeneratedValue(strategy="AUTO")
*/
private $id;
/**
* #var string
* #ORM\Column(name="name", type="string", nullable=false, length=255)
*/
private $name;
/**
* #var boolean
* #ORM\Column(name="pageload", nullable=false, type="boolean")
*/
private $pageload;
/**
* #var integer
* #ORM\Column(name="loadafter", nullable=false, type="integer")
*/
private $loadafter;
/**
* #var boolean
* #ORM\Column(name="exitload", nullable=false, type="boolean")
*/
private $exitload;
/**
* #var integer
* #ORM\Column(name="viewcount", nullable=false, type="integer")
*/
private $viewcount;
/**
* #var integer
* #ORM\Column(name="status", nullable=false, type="integer")
*/
private $status;
/**
* #var integer
* #ORM\Column(name="user_id", nullable=false, type="integer")
*/
private $user_id;
/**
* #ORM\OneToMany(targetEntity="PollFrequency", mappedBy="frequency")
* #ORM\JoinColumn(name="frequency_id", referencedColumnName="id")
*/
private $frequency;
/**
* #var \DateTime
* #ORM\Column(name="createdate", nullable=false, type="datetime")
*/
private $createdate;
/**
* Get id
*
* #return integer
*/
public function getId()
{
return $this->id;
}
/**
* Set name
*
* #param string $name
* #return Poll
*/
public function setName($name)
{
$this->name = $name;
return $this;
}
/**
* Get name
*
* #return string
*/
public function getName()
{
return $this->name;
}
/**
* Set pageload
*
* #param boolean $pageload
* #return Poll
*/
public function setPageload($pageload)
{
$this->pageload = $pageload;
return $this;
}
/**
* Get pageload
*
* #return boolean
*/
public function getPageload()
{
return $this->pageload;
}
/**
* Set loadafter
*
* #param integer $loadafter
* #return Poll
*/
public function setLoadafter($loadafter)
{
$this->loadafter = $loadafter;
return $this;
}
/**
* Get loadafter
*
* #return integer
*/
public function getLoadafter()
{
return $this->loadafter;
}
/**
* Set exitload
*
* #param boolean $exitload
* #return Poll
*/
public function setExitload($exitload)
{
$this->exitload = $exitload;
return $this;
}
/**
* Get exitload
*
* #return boolean
*/
public function getExitload()
{
return $this->exitload;
}
/**
* Set viewcount
*
* #param integer $viewcount
* #return Poll
*/
public function setViewcount($viewcount)
{
$this->viewcount = $viewcount;
return $this;
}
/**
* Get viewcount
*
* #return integer
*/
public function getViewcount()
{
return $this->viewcount;
}
/**
* Set status
*
* #param integer $status
* #return Poll
*/
public function setStatus($status)
{
$this->status = $status;
return $this;
}
/**
* Get status
*
* #return integer
*/
public function getStatus()
{
return $this->status;
}
/**
* Set user_id
*
* #param integer $userId
* #return Poll
*/
public function setUserId($userId)
{
$this->user_id = $userId;
return $this;
}
/**
* Get user_id
*
* #return integer
*/
public function getUserId()
{
return $this->user_id;
}
/**
* Set createdate
*
* #param \DateTime $createdate
* #return Poll
*/
public function setCreatedate($createdate)
{
$this->createdate = $createdate;
return $this;
}
/**
* Get createdate
*
* #return \DateTime
*/
public function getCreatedate()
{
return $this->createdate;
}
/**
* Set frequency
*
* #param \PollBundle\Entity\PollFrequency $frequency
* #return Poll
*/
public function setFrequency(\PollBundle\Entity\PollFrequency $frequency = null)
{
$this->frequency = $frequency;
return $this;
}
/**
* Get frequency
*
* #return \PollBundle\Entity\PollFrequency
*/
public function getFrequency()
{
return $this->frequency;
}
}
Happy Coding to All !
I solved like that. If you need solution. that's it as following:
/**
* #ORM\ManyToOne(targetEntity="PollFrequency", fetch="EAGER")
* #ORM\JoinColumn(name="frequency_id", referencedColumnName="id")
*/
private $frequency;
And also I removed that part of PollFrequency as following:
/**
* #ORM\OneToMany(targetEntity="Poll", mappedBy="poll_frequency")
*/
private $polls;
and everything that related to $polls.
Happy Coding to All!
Related
i have a problem, i don't know where is the problem come from. When i save my data to server, i've got error Call to a member function format() on string.
This is my Controller code:
public function newAction(Request $request)
{
$this->denyAccessUnlessGranted('ROLE_HRM_SALARY_ADJUSTMENT_CREATE');
$corp = $this->getSelectedCorporationEntity();
$entity = new SalaryAdjustment();
$entity->setCorporation($corp);
if ($request->isMethod('POST')) {
$data = json_decode($request->getContent());
dump($data);
//$this->validationBeforeProgress('new', $data, $data->level, '', $data->docType);
$employeeEntity = $this->getDoctrine()->getRepository(Employee::class)->find($data->employee);
$entity->setEmployee($employeeEntity);
$entity->setNumber($data->number);
$entity->setEffectiveDate($data->effectiveDate);
$entity->setReference($data->reference);
$entity->setReferenceNumber($data->referenceNumber);
$entity->setRemarks($data->remarks);
$entity->setApprove(false);
$entity->setVoid(false);
$entity->setCreatedBy($this->getCurrentUser()->getUsername());
$entity->setCreatedDate(new \DateTime());
$em = $this->getEM();
$this->validateEntity($entity);
$em->persist($entity);
$newEntityDetail = $data->detail;
if (count($newEntityDetail) > 0) {
foreach ($newEntityDetail as $item) {
dump($item);
if ($item->newValue > 0 || $item->oldValue > 0){
$entityDetail = new SalaryAdjustmentDetail();
$lookupSalaryEntity = $this->getDoctrine()->getRepository(LookupSalary::class)->find($item->lookupSalaryId);
$entityDetail->setLookupSalary($lookupSalaryEntity);
if ($item->oldEffectiveDate != null) {
$entityDetail->setOldEffectiveDate($item->oldEffectiveDate);
}
$entityDetail->setOldValue($item->oldValue);
$entityDetail->setNewValue($item->newValue);
$entityDetail->setSalaryAdjustment($entity);
$this->validateEntity($entityDetail);
$em->persist($entityDetail);
}
}
} else {
throw new \Exception('Detail must be have minimal 1 row');
}
$em->flush();
}
return new JsonResponse(['data' => 'Done']);
}
the error come from when the code $em->flush(). I feel the problem come from when the code $entityDetail->setOldValue($item->oldValue); and entityDetail->setNewValue($item->newValue); because i'm using decimal type in entity for the first time.
i use 2 entity for save my data, the entity is SalaryAdjustment and SalaryAdjustmentDetail. There is the code:
class SalaryAdjustment
{
/**
* #var int
*
* #ORM\Column(name="id", type="integer")
* #ORM\Id
* #ORM\GeneratedValue(strategy="AUTO")
*/
private $id;
/**
* #ORM\OneToMany(targetEntity="SalaryAdjustmentDetail", mappedBy="salaryAdjustment", cascade={"persist", "remove"})
*/
private $salaryAdjustmentDetail;
public function __construct() {
$this->salaryAdjustmentDetail = new ArrayCollection();
}
/**
* #ORM\ManyToOne(targetEntity="Dsp\DspAppsBundle\Entity\HRM\Employee\Employee")
* #ORM\JoinColumn(name="employee_id", referencedColumnName="id", nullable=false)
*/
private $employee;
/**
* #ORM\ManyToOne(targetEntity="Dsp\DspAdministrationBundle\Entity\Corporation")
* #ORM\JoinColumn(name="corporation_id", referencedColumnName="id", nullable=false)
*/
private $corporation;
/**
* #var string
*
* #ORM\Column(name="number", type="string", length=20)
*/
private $number;
/**
* #var \DateTime
*
* #ORM\Column(name="effective_date", type="date")
*/
private $effectiveDate;
/**
* #var string
*
* #ORM\Column(name="reference", type="string", length=50, nullable=true)
*/
private $reference;
/**
* #var string
*
* #ORM\Column(name="reference_number", type="string", length=100, nullable=true)
*/
private $referenceNumber;
/**
* #var string
*
* #ORM\Column(name="remarks", type="string", length=300, nullable=true)
*/
private $remarks;
/**
* #var bool
*
* #ORM\Column(name="approve", type="boolean")
*/
private $approve;
/**
* #var bool
*
* #ORM\Column(name="void", type="boolean")
*/
private $void;
/**
* #var string
*
* #ORM\Column(name="created_by", type="string", length=50)
*/
private $createdBy;
/**
* #var \DateTime
*
* #ORM\Column(name="created_date", type="datetime")
*/
private $createdDate;
/**
* #var string
*
* #ORM\Column(name="modified_by", type="string", length=50, nullable=true)
*/
private $modifiedBy;
/**
* #var \DateTime
*
* #ORM\Column(name="modified_date", type="datetime", nullable=true)
*/
private $modifiedDate;
/**
* Get id
*
* #return int
*/
public function getId()
{
return $this->id;
}
/**
* Add salaryAdjustmentDetail
*
* #param \Dsp\DspAppsBundle\Entity\HRM\SalaryAdjustment\SalaryAdjustmentDetail $salaryAdjustmentDetail
*
* #return SalaryAdjustment
*/
public function addSalaryAdjustmentDetail(SalaryAdjustmentDetail $salaryAdjustmentDetail)
{
$this->salaryAdjustmentDetail[] = $salaryAdjustmentDetail;
return $this;
}
/**
* Remove salaryAdjustmentDetail
*
* #param \Dsp\DspAppsBundle\Entity\HRM\SalaryAdjustment\SalaryAdjustmentDetail $salaryAdjustmentDetail
*/
public function removeSalaryAdjustmentDetail(\Dsp\DspAppsBundle\Entity\HRM\SalaryAdjustment\SalaryAdjustmentDetail $salaryAdjustmentDetail)
{
$this->salaryAdjustmentDetail->removeElement($salaryAdjustmentDetail);
}
/**
* Set employee
*
* #param \Dsp\DspAppsBundle\Entity\HRM\Employee\Employee $employee
*
* #return SalaryAdjustment
*/
public function setEmployee(\Dsp\DspAppsBundle\Entity\HRM\Employee\Employee $employee)
{
$this->employee = $employee;
return $this;
}
/**
* Get employee
*
* #return \Dsp\DspAppsBundle\Entity\HRM\Employee\Employee
*/
public function getEmployee()
{
return $this->employee;
}
/**
* Set corporation
*
* #param \Dsp\DspAdministrationBundle\Entity\Corporation $corporation
*
* #return SalaryAdjustment
*/
public function setCorporation(\Dsp\DspAdministrationBundle\Entity\Corporation $corporation)
{
$this->corporation = $corporation;
return $this;
}
/**
* Get corporation
*
* #return \Dsp\DspAdministrationBundle\Entity\Corporation
*/
public function getCorporation()
{
return $this->corporation;
}
/**
* Set number
*
* #param string $number
*
* #return SalaryAdjustment
*/
public function setNumber($number)
{
$this->number = $number;
return $this;
}
/**
* Get number
*
* #return string
*/
public function getNumber()
{
return $this->number;
}
/**
* Set effectiveDate
*
* #param \DateTime $effectiveDate
*
* #return SalaryAdjustment
*/
public function setEffectiveDate($effectiveDate)
{
$this->effectiveDate = $effectiveDate;
return $this;
}
/**
* Get effectiveDate
*
* #return \DateTime
*/
public function getEffectiveDate()
{
return $this->effectiveDate;
}
/**
* Set reference
*
* #param string $reference
*
* #return SalaryAdjustment
*/
public function setReference($reference)
{
$this->reference = $reference;
return $this;
}
/**
* Get reference
*
* #return string
*/
public function getReference()
{
return $this->reference;
}
/**
* Set referenceNumber
*
* #param string $referenceNumber
*
* #return SalaryAdjustment
*/
public function setReferenceNumber($referenceNumber)
{
$this->referenceNumber = $referenceNumber;
return $this;
}
/**
* Get referenceNumber
*
* #return string
*/
public function getReferenceNumber()
{
return $this->referenceNumber;
}
/**
* Set remarks
*
* #param string $remarks
*
* #return SalaryAdjustment
*/
public function setRemarks($remarks)
{
$this->remarks = $remarks;
return $this;
}
/**
* Get remarks
*
* #return string
*/
public function getRemarks()
{
return $this->remarks;
}
/**
* Set approve
*
* #param boolean $approve
*
* #return SalaryAdjustment
*/
public function setApprove($approve)
{
$this->approve = $approve;
return $this;
}
/**
* Get approve
*
* #return bool
*/
public function getApprove()
{
return $this->approve;
}
/**
* Set void
*
* #param boolean $void
*
* #return SalaryAdjustment
*/
public function setVoid($void)
{
$this->void = $void;
return $this;
}
/**
* Get void
*
* #return bool
*/
public function getVoid()
{
return $this->void;
}
/**
* Set createdBy
*
* #param string $createdBy
*
* #return SalaryAdjustment
*/
public function setCreatedBy($createdBy)
{
$this->createdBy = $createdBy;
return $this;
}
/**
* Get createdBy
*
* #return string
*/
public function getCreatedBy()
{
return $this->createdBy;
}
/**
* Set createdDate
*
* #param \DateTime $createdDate
*
* #return SalaryAdjustment
*/
public function setCreatedDate($createdDate)
{
$this->createdDate = $createdDate;
return $this;
}
/**
* Get createdDate
*
* #return \DateTime
*/
public function getCreatedDate()
{
return $this->createdDate;
}
/**
* Set modifiedBy
*
* #param string $modifiedBy
*
* #return SalaryAdjustment
*/
public function setModifiedBy($modifiedBy)
{
$this->modifiedBy = $modifiedBy;
return $this;
}
/**
* Get modifiedBy
*
* #return string
*/
public function getModifiedBy()
{
return $this->modifiedBy;
}
/**
* Set modifiedDate
*
* #param \DateTime $modifiedDate
*
* #return SalaryAdjustment
*/
public function setModifiedDate($modifiedDate)
{
$this->modifiedDate = $modifiedDate;
return $this;
}
/**
* Get modifiedDate
*
* #return \DateTime
*/
public function getModifiedDate()
{
return $this->modifiedDate;
}
}
And this is my SalaryAdjustmentDetail:
class SalaryAdjustmentDetail
{
/**
* #var int
*
* #ORM\Column(name="id", type="integer")
* #ORM\Id
* #ORM\GeneratedValue(strategy="AUTO")
*/
private $id;
/**
* #ORM\ManyToOne(targetEntity="Dsp\DspAppsBundle\Entity\HRM\Lookup\LookupSalary")
* #ORM\JoinColumn(name="lookup_salary_id", referencedColumnName="id", nullable=false)
*/
private $lookupSalary;
/**
* #ORM\ManyToOne(targetEntity="Dsp\DspAppsBundle\Entity\HRM\SalaryAdjustment\SalaryAdjustment", inversedBy="SalaryAdjustmentDetail")
* #ORM\JoinColumn(name="salary_adjustment_id", referencedColumnName="id", onDelete="CASCADE", nullable=false)
*/
private $salaryAdjustment;
/**
* #var \DateTime
*
* #ORM\Column(name="old_effective_date", type="date", nullable=true)
*/
private $oldEffectiveDate;
/**
* #var string
*
* #ORM\Column(name="old_value", type="decimal", precision=20, scale=4)
*/
private $oldValue;
/**
* #var string
*
* #ORM\Column(name="new_value", type="decimal", precision=20, scale=4)
*/
private $newValue;
/**
* Get id
*
* #return int
*/
public function getId()
{
return $this->id;
}
/**
* Set lookupSalary
*
* #param \Dsp\DspAppsBundle\Entity\HRM\Lookup\LookupSalary $lookupSalary
*
* #return SalaryAdjustmentDetail
*/
public function setLookupSalary(\Dsp\DspAppsBundle\Entity\HRM\Lookup\LookupSalary $lookupSalary)
{
$this->lookupSalary = $lookupSalary;
return $this;
}
/**
* Get lookupSalary
*
* #return \Dsp\DspAppsBundle\Entity\HRM\Lookup\LookupSalary
*/
public function getLookupSalary()
{
return $this->lookupSalary;
}
/**
* Set salaryAdjustment
*
* #param \Dsp\DspAppsBundle\Entity\HRM\SalaryAdjustment\SalaryAdjustment $salaryAdjustment
*
* #return SalaryAdjustmentDetail
*/
public function setSalaryAdjustment(\Dsp\DspAppsBundle\Entity\HRM\SalaryAdjustment\SalaryAdjustment $salaryAdjustment)
{
$this->salaryAdjustment = $salaryAdjustment;
return $this;
}
/**
* Get salaryAdjustment
*
* #return \Dsp\DspAppsBundle\Entity\HRM\SalaryAdjustment\SalaryAdjustment
*/
public function getSalaryAdjustment()
{
return $this->salaryAdjustment;
}
/**
* Set oldEffectiveDate
*
* #param \DateTime $oldEffectiveDate
*
* #return SalaryAdjustmentDetail
*/
public function setOldEffectiveDate($oldEffectiveDate)
{
$this->oldEffectiveDate = $oldEffectiveDate;
return $this;
}
/**
* Get oldEffectiveDate
*
* #return \DateTime
*/
public function getOldEffectiveDate()
{
return $this->oldEffectiveDate;
}
/**
* Set oldValue
*
* #param string $oldValue
*
* #return SalaryAdjustmentDetail
*/
public function setOldValue($oldValue)
{
$this->oldValue = $oldValue;
return $this;
}
/**
* Get oldValue
*
* #return string
*/
public function getOldValue()
{
return $this->oldValue;
}
/**
* Set newValue
*
* #param string $newValue
*
* #return SalaryAdjustmentDetail
*/
public function setNewValue($newValue)
{
$this->newValue = $newValue;
return $this;
}
/**
* Get newValue
*
* #return string
*/
public function getNewValue()
{
return $this->newValue;
}
}
Please help me for resolve my problem :')
I've got problem with relations ManyToOne.
I have 2 entities:
namespace MyApp\PanelBundle\Entity;
use MyApp\PanelBundle\Entity\SupportMessagesThreads;
use Doctrine\ORM\Mapping as ORM;
/**
* SupportMessages
*
* #ORM\Table(name="support_messages")
* #ORM\Entity(repositoryClass="MyApp\PanelBundle\Repository\SupportMessagesRepository")
*/
class SupportMessages
{
/**
* #var int
*
* #ORM\Column(name="id", type="integer")
* #ORM\Id
* #ORM\GeneratedValue(strategy="AUTO")
*/
private $id;
/**
* #var int
*
* #ORM\Column(name="thread_id", type="integer")
*/
private $thread_id;
/**
* #var int
*
* #ORM\Column(name="sender", type="integer")
*/
private $sender;
/**
* #var string
*
* #ORM\Column(name="content", type="text")
*/
private $content;
/**
* #var bool
*
* #ORM\Column(name="is_read_sender", type="boolean")
*/
private $is_read_sender;
/**
* #var bool
*
* #ORM\Column(name="is_read_recipient", type="boolean")
*/
private $is_read_recipient;
/**
* #var \DateTime
*
* #ORM\Column(name="created", type="datetime")
*/
private $created;
/**
* #ORM\ManyToOne(targetEntity="SupportMessagesThreads", inversedBy="messages")
* #ORM\JoinColumn(name="thread_id", referencedColumnName="id")
*/
private $thread;
/**
* Get id
*
* #return int
*/
public function getId()
{
return $this->id;
}
/**
* Set threadId
*
* #param integer $threadId
*
* #return SupportMessages
*/
public function setThreadId($thread_id)
{
$this->thread_id = $thread_id;
return $this;
}
/**
* Get threadId
*
* #return int
*/
public function getThreadId()
{
return $this->thread_id;
}
/**
* Set sender
*
* #param integer $sender
*
* #return SupportMessages
*/
public function setSender($sender)
{
$this->sender = $sender;
return $this;
}
/**
* Get sender
*
* #return int
*/
public function getSender()
{
return $this->sender;
}
/**
* Set content
*
* #param string $content
*
* #return SupportMessages
*/
public function setContent($content)
{
$this->content = $content;
return $this;
}
/**
* Get content
*
* #return string
*/
public function getContent()
{
return $this->content;
}
/**
* Set isReadSender
*
* #param boolean $isReadSender
*
* #return SupportMessages
*/
public function setIsReadSender($isReadSender)
{
$this->is_read_sender = $isReadSender;
return $this;
}
/**
* Get isReadSender
*
* #return bool
*/
public function getIsReadSender()
{
return $this->is_read_sender;
}
/**
* Set isReadRecipient
*
* #param boolean $isReadRecipient
*
* #return SupportMessages
*/
public function setIsReadRecipient($isReadRecipient)
{
$this->is_read_recipient = $isReadRecipient;
return $this;
}
/**
* Get isReadRecipient
*
* #return bool
*/
public function getIsReadRecipient()
{
return $this->is_read_recipient;
}
/**
* Set created
*
* #param \DateTime $created
*
* #return SupportMessages
*/
public function setCreated($created)
{
$this->created = $created;
return $this;
}
/**
* Get created
*
* #return \DateTime
*/
public function getCreated()
{
return $this->created;
}
}
AND
<?php
namespace MyApp\PanelBundle\Entity;
use Doctrine\ORM\Mapping as ORM;
use Doctrine\Common\Collections\ArrayCollection;
use MyApp\PanelBundle\Entity\SupportMessages;
/**
* SupportMessagesThreads
*
* #ORM\Table(name="support_messages_threads")
* #ORM\Entity(repositoryClass="MyApp\PanelBundle\Repository\SupportMessagesThreadsRepository")
*/
class SupportMessagesThreads
{
/**
* #var int
*
* #ORM\Column(name="id", type="integer")
* #ORM\Id
* #ORM\GeneratedValue(strategy="AUTO")
*/
private $id;
/**
* #var int
*
* #ORM\Column(name="user_id", type="integer")
*/
private $user_id;
/**
* #var int
*
* #ORM\Column(name="recipient", type="integer")
*/
private $recipient;
/**
* #var string
*
* #ORM\Column(name="title", type="string")
*/
private $title;
/**
* #var int
*
* #ORM\Column(name="status", type="integer")
*/
private $status;
/**
* #var \DateTime
*
* #ORM\Column(name="created", type="datetime")
*/
private $created;
/**
* #ORM\OneToMany(targetEntity="SupportMessages", mappedBy="thread")
*/
protected $messages;
public function __construct()
{
$this->messages = new ArrayCollection();
}
/**
* Get id
*
* #return int
*/
public function getId()
{
return $this->id;
}
function getMessages() {
return $this->messages;
}
function setMessages($messages) {
$this->messages = $messages;
}
/**
* Set userId
*
* #param integer $userId
*
* #return SupportMessagesThreads
*/
public function setUserId($userId)
{
$this->user_id = $userId;
return $this;
}
/**
* Get userId
*
* #return int
*/
public function getUserId()
{
return $this->user_id;
}
/**
* Set recipient
*
* #param integer $recipient
*
* #return SupportMessagesThreads
*/
public function setRecipient($recipient)
{
$this->recipient = $recipient;
return $this;
}
/**
* Get recipient
*
* #return int
*/
public function getRecipient()
{
return $this->recipient;
}
/**
* Set title
*
* #param string $title
*
* #return SupportMessagesThreads
*/
public function setTitle($title)
{
$this->title = $title;
return $this;
}
/**
* Get title
*
* #return string
*/
public function getTitle()
{
return $this->title;
}
/**
* Set status
*
* #param integer $status
*
* #return SupportMessagesThreads
*/
public function setStatus($status)
{
$this->status = $status;
return $this;
}
/**
* Get status
*
* #return int
*/
public function getStatus()
{
return $this->status;
}
/**
* Set created
*
* #param \DateTime $created
*
* #return SupportMessagesThreads
*/
public function setCreated($created)
{
$this->created = $created;
return $this;
}
/**
* Get created
*
* #return \DateTime
*/
public function getCreated()
{
return $this->created;
}
}
In My Controller i have This code:
$supportMessageThread = new SupportMessagesThreads();
$supportMessageThread
->setUserId($this->getUser()->getId())
->setStatus(0)
->setTitle($formData->getTitle())
->setRecipient($formData->getRecipient())
->setCreated(new \DateTime());
$supportMessage = new SupportMessages($formData);
$supportMessage
->setThreadId($supportMessageThread)
->setCreated(new \DateTime())
->setIsReadSender(1)
->setIsReadRecipient(0)
->setSender($this->getUser()->getId())
->setContent($formData->message);
$em = $this->getDoctrine()->getManager();
$em->persist($supportMessageThread);
$em->persist($supportMessage);
$em->flush();
My field called in #ORM\JoinColum name returns null every time. When i change "thread_id" to other fields ex. "sender" then "sender" field is null. What i can do to set id of SupportMessageThread entity to thread_id.
Printing data works fine. When i put test records to base manually and the next im get it by doctrine - everything is ok. The problem only occurs when save.
Please Help Me :((
Probably you want to use Cascade operations
And your mapping looks a bit weird. Note that you declare the argument as integer
/**
* Set threadId
*
* #param integer $threadId
*
* #return SupportMessages
*/
public function setThreadId($thread_id)
{
$this->thread_id = $thread_id;
return $this;
}
But SupportMessagesThreads is passed:
->setThreadId($supportMessageThread)
You should use objects instead scalars like
/**
* Set thread
*
* #param SupportMessagesThreads $thread
*
* #return SupportMessages
*/
public function setThread(SupportMessagesThreads $thread)
{
$this->thread = $thread;
return $this;
}
and remove $thread_id field from SupportMessagesThreads
In my case i had incorrect definitions of inversed and mapped by.
In both cases it was the same field todo.
That's the same case in the question above.
After changes it's
/**
* #ORM\OneToMany(targetEntity=MyTodoElement::class, mappedBy="myTodo")
*/
private $myTodoElement;
/**
* #ORM\ManyToOne(targetEntity=MyTodo::class, inversedBy="myTodoElement")
* #ORM\JoinColumn(nullable=false)
*/
private $myTodo;
what's the wrong in this code
i want to create query with multi join but unfortunately this error displayed
[this is my SearchController controller]
class SearchController extends Controller {
public function indexAction() {
$em = $this->get('doctrine.orm.entity_manager');
$users = $em
->createQueryBuilder('P')
->select('P.pname, Q.qname,P.gender,P.phone,P.yearsOfExperience,P.graduationYear,c.cname')
->add('from', 'serachBundle:Person P')
->Join('P.Qualification', 'Q')
->Join('Q.Category', 'c')
->where('P.qualificationId=Q.id')
->andwhere('Q.categoryId=c.id')
->getQuery();
$user = $users->getResult();
print_r($user);
//qualification
$Qlist = $this->getDoctrine()
->getRepository('serachBundle:qualification')
->findAll();
//category
$Catlist = $this->getDoctrine()
->getRepository('serachBundle:category')
->findAll();
return $this->render('serachBundle:Default:Search.html.twig', array('user' => $user, 'Qlist' => $Qlist, 'Catlist' => $Catlist));
}
this my person entity
<?php
namespace Search\serachBundle\Entity;
use Doctrine\ORM\Mapping as ORM;
/**
* Person
*
* #ORM\Table(name="person", indexes={#ORM\Index(name="companyId", columns={"companyId", "qualificationId"}), #ORM\Index(name="qualificationId", columns={"qualificationId"}), #ORM\Index(name="IDX_34DCD1762480E723", columns={"companyId"})})
* #ORM\Entity
*/
class Person
{
/**
* #var string
*
* #ORM\Column(name="pname", type="string", length=255, nullable=false)
*/
private $pname;
/**
* #var string
*
* #ORM\Column(name="address", type="string", length=255, nullable=false)
*/
private $address;
/**
* #var string
*
* #ORM\Column(name="phone", type="string", length=255, nullable=false)
*/
private $phone;
/**
* #var string
*
* #ORM\Column(name="gender", type="string", length=255, nullable=false)
*/
private $gender;
/**
* #var integer
*
* #ORM\Column(name="yearsOfExperience", type="integer", nullable=false)
*/
private $yearsofexperience;
/**
* #var integer
*
* #ORM\Column(name="graduationYear", type="integer", nullable=false)
*/
private $graduationyear;
/**
* #var integer
*
* #ORM\Column(name="id", type="integer")
* #ORM\Id
* #ORM\GeneratedValue(strategy="IDENTITY")
*/
private $id;
/**
* #var \Search\serachBundle\Entity\Company
*
* #ORM\ManyToOne(targetEntity="Search\serachBundle\Entity\Company")
* #ORM\JoinColumns({
* #ORM\JoinColumn(name="companyId", referencedColumnName="id")
* })
*/
private $companyid;
/**
* #var \Search\serachBundle\Entity\Qualification
*
* #ORM\ManyToOne(targetEntity="Search\serachBundle\Entity\Qualification")
* #ORM\JoinColumns({
* #ORM\JoinColumn(name="qualificationId", referencedColumnName="id")
* })
*/
private $qualificationid;
/**
* Set pname
*
* #param string $pname
* #return Person
*/
public function setPname($pname)
{
$this->pname = $pname;
return $this;
}
/**
* Get pname
*
* #return string
*/
public function getPname()
{
return $this->pname;
}
/**
* Set address
*
* #param string $address
* #return Person
*/
public function setAddress($address)
{
$this->address = $address;
return $this;
}
/**
* Get address
*
* #return string
*/
public function getAddress()
{
return $this->address;
}
/**
* Set phone
*
* #param string $phone
* #return Person
*/
public function setPhone($phone)
{
$this->phone = $phone;
return $this;
}
/**
* Get phone
*
* #return string
*/
public function getPhone()
{
return $this->phone;
}
/**
* Set gender
*
* #param string $gender
* #return Person
*/
public function setGender($gender)
{
$this->gender = $gender;
return $this;
}
/**
* Get gender
*
* #return string
*/
public function getGender()
{
return $this->gender;
}
/**
* Set yearsofexperience
*
* #param integer $yearsofexperience
* #return Person
*/
public function setYearsofexperience($yearsofexperience)
{
$this->yearsofexperience = $yearsofexperience;
return $this;
}
/**
* Get yearsofexperience
*
* #return integer
*/
public function getYearsofexperience()
{
return $this->yearsofexperience;
}
/**
* Set graduationyear
*
* #param integer $graduationyear
* #return Person
*/
public function setGraduationyear($graduationyear)
{
$this->graduationyear = $graduationyear;
return $this;
}
/**
* Get graduationyear
*
* #return integer
*/
public function getGraduationyear()
{
return $this->graduationyear;
}
/**
* Get id
*
* #return integer
*/
public function getId()
{
return $this->id;
}
/**
* Set companyid
*
* #param \Search\serachBundle\Entity\Company $companyid
* #return Person
*/
public function setCompanyid(\Search\serachBundle\Entity\Company $companyid = null)
{
$this->companyid = $companyid;
return $this;
}
/**
* Get companyid
*
* #return \Search\serachBundle\Entity\Company
*/
public function getCompanyid()
{
return $this->companyid;
}
/**
* Set qualificationid
*
* #param \Search\serachBundle\Entity\Qualification $qualificationid
* #return Person
*/
public function setQualificationid(\Search\serachBundle\Entity\Qualification $qualificationid = null)
{
$this->qualificationid = $qualificationid;
return $this;
}
/**
* Get qualificationid
*
* #return \Search\serachBundle\Entity\Qualification
*/
public function getQualificationid()
{
return $this->qualificationid;
}
}
(Entities are objects with identity. Their identity has a conceptual meaning inside your domain. In a CMS application each article has a unique id. You can uniquely identify each article by that id.)
this my Qualification entity
<?php
namespace Search\serachBundle\Entity;
use Doctrine\ORM\Mapping as ORM;
/**
* Qualification
*
* #ORM\Table(name="qualification", indexes={#ORM\Index(name="categoryId", columns={"categoryId"})})
* #ORM\Entity
*/
class Qualification
{
/**
* #var string
*
* #ORM\Column(name="qname", type="string", length=255, nullable=false)
*/
private $qname;
/**
* #var string
*
* #ORM\Column(name="specialty", type="string", length=255, nullable=false)
*/
private $specialty;
/**
* #var string
*
* #ORM\Column(name="qualifDesc", type="string", length=255, nullable=false)
*/
private $qualifdesc;
/**
* #var integer
*
* #ORM\Column(name="id", type="integer")
* #ORM\Id
* #ORM\GeneratedValue(strategy="IDENTITY")
*/
private $id;
/**
* #var \Search\serachBundle\Entity\Category
*
* #ORM\ManyToOne(targetEntity="Search\serachBundle\Entity\Category")
* #ORM\JoinColumns({
* #ORM\JoinColumn(name="categoryId", referencedColumnName="id")
* })
*/
private $categoryid;
/**
* Set qname
*
* #param string $qname
* #return Qualification
*/
public function setQname($qname)
{
$this->qname = $qname;
return $this;
}
/**
* Get qname
*
* #return string
*/
public function getQname()
{
return $this->qname;
}
/**
* Set specialty
*
* #param string $specialty
* #return Qualification
*/
public function setSpecialty($specialty)
{
$this->specialty = $specialty;
return $this;
}
/**
* Get specialty
*
* #return string
*/
public function getSpecialty()
{
return $this->specialty;
}
/**
* Set qualifdesc
*
* #param string $qualifdesc
* #return Qualification
*/
public function setQualifdesc($qualifdesc)
{
$this->qualifdesc = $qualifdesc;
return $this;
}
/**
* Get qualifdesc
*
* #return string
*/
public function getQualifdesc()
{
return $this->qualifdesc;
}
/**
* Get id
*
* #return integer
*/
public function getId()
{
return $this->id;
}
/**
* Set categoryid
*
* #param \Search\serachBundle\Entity\Category $categoryid
* #return Qualification
*/
public function setCategoryid(\Search\serachBundle\Entity\Category $categoryid = null)
{
$this->categoryid = $categoryid;
return $this;
}
/**
* Get categoryid
*
* #return \Search\serachBundle\Entity\Category
*/
public function getCategoryid()
{
return $this->categoryid;
}
}
Thanks in advance if anyone can solve this. It would be a really great help
You named the relations as $qualificationid, so you should make your query something like this:
->Join('P.qualificationid', 'Q')
->Join('Q.categoryid', 'c')
Remember to make all queries inside repositories classes. And please, try to rename your bundle from serach to search :-D
I've two doctrine entities with ManyToOne relationship:
/**
* #ORM\ManyToOne(targetEntity="Iballot\CmsBundle\Entity\PollingStation2", cascade={"persist"})
* #ORM\JoinColumn(nullable=false)
* #Expose
*/
private $pollingStation2;
and I'd like get a specific one result for a given PollingStation2 ID and I've try that but doesn't work:
public function getPresidential($polId)
{
$qb = $this->createQueryBuilder('r');
$qb->where('r.pollingStation2 = :polling_station2_id')
->setParameter('polling_station2_id', $polId);
return $qb->getQuery()
->getResult();
}
Entities
namespace Iballot\CmsBundle\Entity;
use Doctrine\ORM\Mapping as ORM;
/**
* PollingStation2
*
* #ORM\Table()
* #ORM\Entity(repositoryClass="Iballot\CmsBundle\Entity\PollingStation2Repository")
*/
class PollingStation2
{
/**
* #var integer
*
* #ORM\Column(name="id", type="integer")
* #ORM\Id
* #ORM\GeneratedValue(strategy="AUTO")
*/
private $id;
/**
* #var string
*
* #ORM\Column(name="verfierNumber", type="integer", length=255, nullable=true)
*/
protected $verfierNumber;
/**
* #var string
*
* #ORM\Column(name="name", type="string", length=255)
*/
private $name;
/**
* #var string
*
* #ORM\Column(name="verifier_number", type="string", length=255)
*/
private $verifierNumber;
/**
* #var string
*
* #ORM\Column(name="address", type="string", length=255)
*/
private $address;
/**
* #ORM\OneToMany(targetEntity="Iballot\CmsBundle\Entity\PollingStation2", mappedBy="pollingStation")
*/
protected $result;
/**
* #ORM\ManyToOne(targetEntity="Iballot\CmsBundle\Entity\Constituency", cascade={"persist"})
* #ORM\JoinColumn(nullable=false)
*/
private $constituency;
/**
* Get id
*
* #return integer
*/
public function getId()
{
return $this->id;
}
public function __toString() {
return $this->getName();
}
/**
* Set name
*
* #param string $name
*
* #return PollingStation2
*/
public function setName($name)
{
$this->name = $name;
return $this;
}
/**
* Get name
*
* #return string
*/
public function getName()
{
return $this->name;
}
/**
* Set address
*
* #param string $address
*
* #return PollingStation2
*/
public function setAddress($address)
{
$this->address = $address;
return $this;
}
/**
* Get address
*
* #return string
*/
public function getAddress()
{
return $this->address;
}
/**
* Set verifierNumber
*
* #param integer $verifierNumber
*
* #return PollingStation2
*/
public function setVerifierNumber($verifierNumber)
{
$this->verifierNumber = $verifierNumber;
return $this;
}
/**
* Get verifierNumber
*
* #return integer
*/
public function getVerifierNumber()
{
return $this->verifierNumber;
}
/**
* Set verfierNumber
*
* #param integer $verfierNumber
*
* #return PollingStation2
*/
public function setVerfierNumber($verfierNumber)
{
$this->verfierNumber = $verfierNumber;
return $this;
}
/**
* Get verfierNumber
*
* #return integer
*/
public function getVerfierNumber()
{
return $this->verfierNumber;
}
/**
* Set constituency
*
* #param \Iballot\CmsBundle\Entity\Constituency $constituency
*
* #return PollingStation2
*/
public function setConstituency(\Iballot\CmsBundle\Entity\Constituency $constituency)
{
$this->constituency = $constituency;
return $this;
}
/**
* Get constituency
*
* #return \Iballot\CmsBundle\Entity\Constituency
*/
public function getConstituency()
{
return $this->constituency;
}
/**
* Constructor
*/
public function __construct()
{
$this->result = new \Doctrine\Common\Collections\ArrayCollection();
}
/**
* Add result
*
* #param \Iballot\CmsBundle\Entity\PollingStation2 $result
*
* #return PollingStation2
*/
public function addResult(\Iballot\CmsBundle\Entity\PollingStation2 $result)
{
$this->result[] = $result;
return $this;
}
/**
* Remove result
*
* #param \Iballot\CmsBundle\Entity\PollingStation2 $result
*/
public function removeResult(\Iballot\CmsBundle\Entity\PollingStation2 $result)
{
$this->result->removeElement($result);
}
/**
* Get result
*
* #return \Doctrine\Common\Collections\Collection
*/
public function getResult()
{
return $this->result;
}
}
Excuse me for my English.
I have 3 classes: User, Category and Service.
When I do even a simple query to the database for Service, for example findAll(), my computer hangs... At the same time, the query for Category and User are good.
Thank you for your help!
User.php
namespace General\UserBundle\Entity;
use Doctrine\ORM\Mapping as ORM;
use FOS\UserBundle\Model\User as BaseUser;
use Symfony\Component\Validator\Constraints as Assert;
/**
* #ORM\Entity
* #ORM\Table(name="user")
*/
class User extends BaseUser
{
/**
* #var integer
*
* #ORM\Column(name="id", type="integer")
* #ORM\Id
* #ORM\GeneratedValue(strategy="AUTO")
*/
protected $id;
/**
* #ORM\Column(type="string", length=255)
*
* #Assert\NotBlank(message="Please enter your type.", groups={"Registration", "Profile"})
* #Assert\Length(
* min=3,
* max="255",
* minMessage="The type is too short.",
* maxMessage="The type is too long.",
* groups={"Registration", "Profile"}
* )
*/
protected $type;
/**
* Get id
*
* #return integer
*/
public function getId()
{
return $this->id;
}
/**
* Set type
*
* #param string $type
* #return User
*/
public function setType($type)
{
$this->type = $type;
return $this;
}
/**
* Get type
*
* #return string
*/
public function getType()
{
return $this->type;
}
}
Category.php
namespace General\AnnuaireBundle\Entity;
use Doctrine\ORM\Mapping as ORM;
use Doctrine\Common\Collections\ArrayCollection;
/**
* Category
*
* #ORM\Table()
* #ORM\Entity(repositoryClass="General\AnnuaireBundle\Entity\CategoryRepository")
*/
class Category
{
/**
* #var integer
*
* #ORM\Column(name="id", type="integer")
* #ORM\Id
* #ORM\GeneratedValue(strategy="AUTO")
*/
private $id;
/**
* #var string
*
* #ORM\Column(name="name", type="string", length=255)
*/
private $name;
/**
* #var string
*
* #ORM\Column(name="description", type="text")
*/
private $description;
/**
* #var boolean
*
* #ORM\Column(name="statut", type="boolean")
*/
private $statut;
/**
* #var \DateTime
*
* #ORM\Column(name="created_at", type="datetime")
*/
private $createdAt;
/**
* #ORM\OneToMany(targetEntity="\General\AnnuaireBundle\Entity\Service", mappedBy="categories")
*/
private $services;
/**
* Constructor
*/
public function __construct() {
$this->createdAt = new \DateTime();
$this->services = new ArrayCollection();
}
/**
* Get id
*
* #return integer
*/
public function getId()
{
return $this->id;
}
/**
* Set name
*
* #param string $name
* #return Category
*/
public function setName($name)
{
$this->name = $name;
return $this;
}
/**
* Get name
*
* #return string
*/
public function getName()
{
return $this->name;
}
/**
* Set description
*
* #param string $description
* #return Category
*/
public function setDescription($description)
{
$this->description = $description;
return $this;
}
/**
* Get description
*
* #return string
*/
public function getDescription()
{
return $this->description;
}
/**
* Set statut
*
* #param boolean $statut
* #return Category
*/
public function setStatut($statut)
{
$this->statut = $statut;
return $this;
}
/**
* Get statut
*
* #return boolean
*/
public function getStatut()
{
return $this->statut;
}
/**
* #ORM\PrePersist()
*/
public function setCreatedAt($createdAt = null) {
$this->createdAt = null === $createdAt ? new \DateTime() : $createdAt;
return $this;
}
/**
* Get createdAt
*
* #return \DateTime
*/
public function getCreatedAt()
{
return $this->createdAt;
}
/**
* Add services
*
* #param \General\AnnuaireBundle\Entity\Service $services
* #return Category
*/
public function addService(\General\AnnuaireBundle\Entity\Service $services)
{
$this->services[] = $services;
return $this;
}
/**
* Remove services
*
* #param \General\AnnuaireBundle\Entity\Service $services
*/
public function removeService(\General\AnnuaireBundle\Entity\Service $services)
{
$this->services->removeElement($services);
}
/**
* Get services
*
* #return \Doctrine\Common\Collections\Collection
*/
public function getServices()
{
return $this->services;
}
}
Service.php
namespace General\AnnuaireBundle\Entity;
use Doctrine\ORM\Mapping as ORM;
/**
* Service
*
* #ORM\Table()
* #ORM\Entity(repositoryClass="General\AnnuaireBundle\Entity\ServiceRepository")
*/
class Service
{
/**
* #var integer
*
* #ORM\Column(name="id", type="integer")
* #ORM\Id
* #ORM\GeneratedValue(strategy="AUTO")
*/
private $id;
/**
* #var string
*
* #ORM\Column(name="name", type="string", length=255)
*/
private $name;
/**
* #var string
*
* #ORM\Column(name="description", type="text")
*/
private $description;
/**
* #var boolean
*
* #ORM\Column(name="statut", type="boolean")
*/
private $statut;
/**
* #var \DateTime
*
* #ORM\Column(name="created_at", type="datetime")
*/
private $createdAt;
/**
* #ORM\ManyToOne(targetEntity="\General\AnnuaireBundle\Entity\Category", inversedBy="services")
* #ORM\JoinColumn(name="category_id", referencedColumnName="id")
*/
private $categories;
/**
* #ORM\ManyToOne(targetEntity="\General\UserBundle\Entity\User")
*/
private $users;
/**
* Constructor
*/
public function __construct() {
$this->createdAt = new \DateTime();
}
/**
* Get id
*
* #return integer
*/
public function getId()
{
return $this->id;
}
/**
* Set name
*
* #param string $name
* #return Service
*/
public function setName($name)
{
$this->name = $name;
return $this;
}
/**
* Get name
*
* #return string
*/
public function getName()
{
return $this->name;
}
/**
* Set description
*
* #param string $description
* #return Service
*/
public function setDescription($description)
{
$this->description = $description;
return $this;
}
/**
* Get description
*
* #return string
*/
public function getDescription()
{
return $this->description;
}
/**
* Set statut
*
* #param boolean $statut
* #return Service
*/
public function setStatut($statut)
{
$this->statut = $statut;
return $this;
}
/**
* Get statut
*
* #return boolean
*/
public function getStatut()
{
return $this->statut;
}
/**
* Set createdAt
*
* #param \DateTime $createdAt
* #return Service
*/
public function setCreatedAt($createdAt)
{
$this->createdAt = $createdAt;
return $this;
}
/**
* Get createdAt
*
* #return \DateTime
*/
public function getCreatedAt()
{
return $this->createdAt;
}
/**
* Set categories
*
* #param \General\AnnuaireBundle\Entity\Category $categories
* #return Service
*/
public function setCategories(\General\AnnuaireBundle\Entity\Category $categories = null)
{
$this->categories = $categories;
return $this;
}
/**
* Get categories
*
* #return \General\AnnuaireBundle\Entity\Category
*/
public function getCategories()
{
return $this->categories;
}
/**
* Set users
*
* #param \General\UserBundle\Entity\User $users
* #return Service
*/
public function setUsers(\General\UserBundle\Entity\User $users = null)
{
$this->users = $users;
return $this;
}
/**
* Get users
*
* #return \General\UserBundle\Entity\User
*/
public function getUsers()
{
return $this->users;
}
}
Controller.php
public function showServicesAction()
{
$em = $this->getDoctrine()->getManager();
$services = $em->getRepository('GeneralAnnuaireBundle:Service')->findAll();
return $this->render('GeneralAnnuaireBundle:General:list_services.html.twig',
array('services'=>$services,
)
);
}
If I modified my function as:
$user = $this->container->get('security.context')->getToken()->getUser();
$user_id = $user->getId();
// var_dump($user_id); ALL IS RIGHT
$em = $this->getDoctrine()->getManager();
$services = $em->getRepository('GeneralAnnuaireBundle:Service')->findAll();
// var_dump($user_id); ALL IS RIGHT
// IF: var_dump($services[0]); COMPUTER HUNGS
// IF: echo count($services); RESPONSE RIGHT
// IF:
return $this->render('GeneralAnnuaireBundle:General:list_services.html.twig',
array('services'=>$services, ));
// SCREEN WHITE
If you print object in browser it get hanged because symphony object contains lots of info. suppose if you have relation with other tables it will have current tables info as well as other related tables info (Schema, Data, Relationship etc.) as well so it might 99% chance to hanged the browser. Better to print "echo count($services)" to check object exists or not.
Try Debug::dump($service) or any variable - you will be able to see the objects (without the proxy)