I have to entities, Applications and Votes.
The idea is to relate many to one. So Applications have many Votes and one Vote is for one Application.
In my entities class I have settings like this:
Application Entity Class:
\/**
\* @ORM\OneToMany(targetEntity="Vote", mappedBy="application")
\*/
\private $votes;
Vote Entity Class:
\/**
\* @ORM\ManyToOne(targetEntity="Application", inversedBy="votes")
\* @ORM\JoinColumn(referencedColumnName="id")
\*/
\private $application;
I think this relation is set up well or am I mistaken ?
Next thing is that I have a form builder class for only one field:
$builder->add('rate')
->add('save', 'submit');
The Votes entity has fields: (id, username, rate, createdAt, updatedAt, application)
and in my controller I'm doing something like this:
$vote = new Vote();
$form = $this->createForm(new VoteType(), $vote);
$form->handleRequest($this->getRequest());
if ($form->isValid()) {
$vote->setUserName($tenant->getUsername());
$vote->setApplication($app);
$em->persist($vote);
$em->flush();
$this->get('session')->getFlashBag()->add('success', 'Oceniono aplikację.');
return $this->redirect($this->generateUrl('applications_main'));
}
return array( 'form' => $form->createView(), );
and it isn't working, it returns me error:
ContextErrorException: Warning: json_encode(): recursion detected in E:\wamp\www\project\vendor\symfony\symfony\src\Symfony\Component\HttpFoundation\JsonResponse.php line 92
stack trace (plain text): http://pastebin.com/bSQTDJQY