Ruben de Vries
2011-05-28 16:54:23 UTC
I've been going at this problem for hours now so I figured I better
just ask for help to avoid my head exploding soon ...
I'll paste some snippets and then try to explain.
oneToMany:
comments:
targetEntity: DemoComment
mappedBy: author
cascade: ["persist"]
GoGreat\DemoBundle\Entity\DemoComment:
manyToOne:
author:
targetEntity: DemoUser
inversedBy: comments
public function addComments($comments)
{
$comments->setAuthor($this);
$this->comments[] = $comments;
}
}
public function buildForm(FormBuilder $builder, array $options)
{
$builder->add('name', 'text');
$builder->add('comments', 'entity', array(
'class' => 'GoGreat\DemoBundle\Entity\DemoComment',
'property' => 'body',
'expanded' => true,
'multiple' => true,
));
}
}
$comment = new DemoComment();
$user->addComments($comment);
$em->persist($user);
$em->flush();
$request = $this->get('request');
$user = new DemoUser();
$em = $this->get('doctrine.orm.entity_manager');
$form->setData($user);
if ($request->getMethod() == 'POST') {
$form->bindRequest($request);
if ($form->isValid()) {
foreach ($user->getComments() as $comment) {
var_dump($comment->getBody(), $comment->getAuthor());
}
$em->persist($user);
$em->flush();
}
}
the var_dump just before the persist does throw out the body, but it
doesn't have an author.
I think the form isn't using DemoUser->addComments to set the
comments, but how else could it set the comments?
What am I doing wrong?
If the examples aren't clear enough I can put the demo bundle on
github for you to check ...
--
If you want to report a vulnerability issue on symfony, please send it to security at symfony-project.com
You received this message because you are subscribed to the Google
Groups "symfony users" group.
To post to this group, send email to symfony-users-/***@public.gmane.org
To unsubscribe from this group, send email to
symfony-users+unsubscribe-/***@public.gmane.org
For more options, visit this group at
http://groups.google.com/group/symfony-users?hl=en
just ask for help to avoid my head exploding soon ...
I'll paste some snippets and then try to explain.
yaml mapping for doctrime ORM
GoGreat\DemoBundle\Entity\DemoUser:oneToMany:
comments:
targetEntity: DemoComment
mappedBy: author
cascade: ["persist"]
GoGreat\DemoBundle\Entity\DemoComment:
manyToOne:
author:
targetEntity: DemoUser
inversedBy: comments
DemoUser entity
class GoGreat\DemoBundle\Entity\DemoUser {public function addComments($comments)
{
$comments->setAuthor($this);
$this->comments[] = $comments;
}
}
DemoUserType form
class GoGreat\DemoBundle\Form\DemoUserType {public function buildForm(FormBuilder $builder, array $options)
{
$builder->add('name', 'text');
$builder->add('comments', 'entity', array(
'class' => 'GoGreat\DemoBundle\Entity\DemoComment',
'property' => 'body',
'expanded' => true,
'multiple' => true,
));
}
}
this does work
$user = new DemoUser();$comment = new DemoComment();
$user->addComments($comment);
$em->persist($user);
$em->flush();
this doesn't work
$form = $this->get('form.factory')->create(new DemoUserType());$request = $this->get('request');
$user = new DemoUser();
$em = $this->get('doctrine.orm.entity_manager');
$form->setData($user);
if ($request->getMethod() == 'POST') {
$form->bindRequest($request);
if ($form->isValid()) {
foreach ($user->getComments() as $comment) {
var_dump($comment->getBody(), $comment->getAuthor());
}
$em->persist($user);
$em->flush();
}
}
the var_dump just before the persist does throw out the body, but it
doesn't have an author.
I think the form isn't using DemoUser->addComments to set the
comments, but how else could it set the comments?
What am I doing wrong?
If the examples aren't clear enough I can put the demo bundle on
github for you to check ...
--
If you want to report a vulnerability issue on symfony, please send it to security at symfony-project.com
You received this message because you are subscribed to the Google
Groups "symfony users" group.
To post to this group, send email to symfony-users-/***@public.gmane.org
To unsubscribe from this group, send email to
symfony-users+unsubscribe-/***@public.gmane.org
For more options, visit this group at
http://groups.google.com/group/symfony-users?hl=en