Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 9199681
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 17, 20262026-06-17T22:35:23+00:00 2026-06-17T22:35:23+00:00

I am trying to set up some embedded forms using this guide. I have

  • 0

I am trying to set up some embedded forms using this guide.
I have two models set up in my application, Lesson and Evaluation.

Each Lesson can have multiple Evaluations.

I have a form set up where the user can create a lesson and also as many evaluations as they want within that lesson. When the form is submitted, it creates the lesson record and all of the evaluation records successfully, however the evaluation records that get created are not linked to the parent lesson (the lesson_id field is just left blank).

Can anyone help?

Any advice appreciated.

Thanks.

My Model classes are set up like this:

Evaluation:

class Evaluation
{
    /**
     * @var integer
     *
     * @ORM\Column(name="id", type="integer")
     * @ORM\Id
     * @ORM\GeneratedValue(strategy="AUTO")
     */
    private $id;

    /**
     * @ORM\ManyToOne(targetEntity="Lesson", inversedBy="evaluations")
     * @ORM\JoinColumn(name="lesson_id", referencedColumnName="id")
     */
    protected $lesson;

/**
     * Set lesson
     *
     * @param \LessonBundle\Entity\Lesson $lesson
     * @return Evaluation
     */
    public function setLesson(\LessonBundle\Entity\Lesson $lesson = null)
    {
        $this->lesson = $lesson;

        return $this;
    }

    /**
     * Get lesson
     *
     * @return \LessonBundle\Entity\Lesson 
     */
    public function getLesson()
    {
        return $this->lesson;
    }
}

And the Lesson:

class Lesson
{
    /**
     * @var integer
     *
     * @ORM\Column(name="id", type="integer")
     * @ORM\Id
     * @ORM\GeneratedValue(strategy="AUTO")
     */
    private $id;

    /**
     * @ORM\OneToMany(targetEntity="Evaluation", mappedBy="lesson", cascade={"persist"})
     */
    protected $evaluations;

    public function __construct()
    {
        $this->evaluations = new ArrayCollection();
    }


    /**
     * Get id
     *
     * @return integer 
     */
    public function getId()
    {
        return $this->id;
    }

    /**
     * Add evaluations
     *
     * @param \DS\LessonBundle\Entity\Evaluation $evaluations
     * @return Lesson
     */
    public function addEvaluation(\LessonBundle\Entity\Evaluation $evaluations)
    {
        $this->evaluations[] = $evaluations;

        return $this;
    }

    /**
     * Remove evaluations
     *
     * @param \DS\LessonBundle\Entity\Evaluation $evaluations
     */
    public function removeEvaluation(\LessonBundle\Entity\Evaluation $evaluations)
    {
        $this->evaluations->removeElement($evaluations);
    }

    /**
     * Get evaluations
     *
     * @return \Doctrine\Common\Collections\Collection 
     */
    public function getEvaluations()
    {
        return $this->evaluations;
    }

    public function setEvaluations(ArrayCollection $evaluations)
    {
        foreach ($evaluations as $evaluation) {
            $evaluation->setLesson($this);
        }

        $this->evaluations = $evaluations;
    }
}

My Controller method:

public function newAction()
{
$lesson = new Lesson;

$evaluation1 = new Evaluation();
$lesson->getEvaluations()->add($evaluation1);
$form    = $this->createForm(new LessonType(), $lesson);
$request = $this->getRequest();

if ($request->getMethod() == 'POST') {
    $form->bindRequest($request);

    if ($form->isValid()) {

        $em = $this->getDoctrine()->getEntityManager();
        $em->persist($lesson);
        $em->flush();

        return $this->redirect($this->generateUrl('lesson_list'));
    }
}

return $this->render('LessonBundle:Lesson:new.html.twig', array('form' => $form->createView()));

}

And my forms:

class LessonType extends AbstractType
{
    public function buildForm(FormBuilderInterface $builder, array $options)
    {
        $builder->add('evaluations', 'collection', array(
                                            'type' => new EvaluationType(),
                                            'allow_add' => true,
                                            'by_reference' => false,
                                            ));
    }

    public function getDefaultOptions(array $options)
    {
        return array(
            'data_class' => 'LessonBundle\Entity\Lesson',
        );
    }

    public function getName()
    {
        return 'Lesson';
    }
}

And:

class EvaluationType extends AbstractType
{
    public function buildForm(FormBuilderInterface $builder, array $options)
    {
        $builder->add('report');
    }

    public function getDefaultOptions(array $options)
    {
        return array(
            'data_class' => 'LessonBundle\Entity\Evaluation',
        );
    }

    public function getName()
    {
        return 'Evaluation';
    }
}

And finally, my form twig template:

{% extends '::base.html.twig' %}

{% block content %}
<form class="vertical" action="" method="post" {{ form_enctype(form) }}>
    {{ form_errors(form) }}

    <ul class="collectionholder" data-prototype="{{ form_widget(form.evaluations.vars.prototype)|e }}">
    {% for evaluation in form.evaluations %}

        <li>{{ form_row(evaluation) }}</li>

    {% endfor %}
    </ul>
    {{ form_rest(form) }}
    <input type="submit" />
</form>
{% endblock %}
  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-17T22:35:25+00:00Added an answer on June 17, 2026 at 10:35 pm

    In your class Lesson entity add:

    /**
     * Add evaluations
     *
     * @param \DS\LessonBundle\Entity\Evaluation $evaluations
     * @return Lesson
     */
    public function addEvaluation(\LessonBundle\Entity\Evaluation $evaluations)
    {
        $this->evaluations[] = $evaluations;
    
        $evaluations->setLesson($this);
    
    
        return $this;
    }
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I'm trying to set some custom AWS CloudWatch metrics using the Java SDK. I
I'm using Extjs 3.4. When some details are loaded, I'm trying to set some
I have a Perl script that's trying to set some configured DateTime and DateTime::Duration
I am trying to set some default values for an object using after_initialize .
I am trying to set some session variable in Yii using the following code
I'm trying to set some javascript data (json) in my markup by calling a
I am trying to set some text on a label descriptionLabel.text = [NSString stringWithFormat:mySTUser.bio];
I am trying to set some default inherited permissions to a directory that will
I'm iterating through some objects and trying to set some properties that, apparently, don't
In my ruby(1.9.3) on rails (3.1) app I'm trying to set some conditional behavior

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.