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 8731741
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 13, 20262026-06-13T09:18:23+00:00 2026-06-13T09:18:23+00:00

Orm/Yaml Subject: type: entity repositoryClass: My\SampleBundle\Repository\SubjectRepository id: id: type: integer generator: { strategy: AUTO

  • 0

Orm/Yaml

Subject:
    type: entity
    repositoryClass: My\SampleBundle\Repository\SubjectRepository
    id:
        id:
            type: integer
            generator: { strategy: AUTO }
    fields:
        body:
            type: text
    oneToMany:
        choices:
            targetEntity: Choice
            mappedBy: subject
            cascade: ["persist", "remove"]
Choice:
    type: entity
    repositoryClass: My\SampleBundle\Repository\ChoiceRepository
    id:
        id:
            type: integer
            generator: { strategy: AUTO }
    fields:
        choice:
            type: text
    manyToOne:
        subject:
            targetEntity: Subject
            inversedBy: choices
            joinColumn:
                name: subject_id
                referencedColumnName: id

View

<form action="{{ path('path_create or path_edit', {'id': id}) }}" method="post" {{ form_enctype(form) }}>

    // ...

    <ul id="choice-list" data-prototype="{{ form_widget(form.choices.vars.prototype.choice) | e }}">
        {% for choice in form.choices %}
            <li>
                <div class="errors">
                    {{ form_errors(choice.choice) }}
                </div>
                {{ form_widget(choice.choice) }}
            </li>
        {% endfor %}
    </ul>

    <!-- ## The field can be added by JavaScript. -->
    <span class="add-another-choice">Add another choice</span>
    {{ form_rest(form) }}
    <input type="submit" class="_button" />
</form>

Form/Type

class SubjectType extends AbstractType
{
    public function buildForm(FormBuilderInterface $builder, array $options)
    {
        $builder->add('body', 'textarea');
        $builder->add('choices', 'collection', array(
            'type' => new ChoiceType(),
            'options' => array(
                'required'  => false
            ),
            'allow_add' => true,
            'by_reference' => false,
            'allow_delete' => true,
            'prototype' => true
        ));
    }

    // ...
}

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

    // ...
}

Validation

Subject:
    properties:
        body:
            - NotBlank: ~
            - MinLength: 8
        choices:
            - Valid: ~
Choice:
    properties:
        choice:
            - NotBlank: ~

Controller

public function createAction(Request $request, $id)
{
    $em = $this->get('doctrine')->getEntityManager();

    $subject = new Subject();
    $subject->getChoices()->add(new Choice());

    $form = $this->createForm(new SubjectType(), $subject);

    if ($request->getMethod() == 'POST') {
        $form->bindRequest($request);           //<= error on this point. Why?
                                                // if there is the empty field.
        if ($form->isValid()) {
            return // ...
        }
    }

    return $this->render('MySampleBundle:Subject:create.html.twig', array(
        'form' => $form->createView(),
    ));
}

I try collection form of symfony2.
But, when the field is increased by Javascript, it will fail, if there is the empty field.
When the field is increased, it is before execution of validation and becomes an error. (Catchable Fatal Error:))

How can I manage to achieve that?


EDIT:

If the value is set up, two or more registration will be successful.
If there is an item to which the value is not set, two or more registration will go wrong.
bindRequest function failed.
If only the part of an empty value adds an entity, it will be successful.
However, it seems that it is not right way.

  • 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-13T09:18:24+00:00Added an answer on June 13, 2026 at 9:18 am

    Remove required=false from choice form field or add nullable=true to schema choice field

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

Are ORM frameworks such as Entity Framework, Linq to SQL, Subsonic, NHibernate promote good
I am currently using this to generate my yaml: doctrine orm:convert-mapping --force --from-database yml
In most MVC/ORM type systems django's views.py might be referred to as a controller,
I'm writing an ORM and am unsure of the expected behaviour of the Repository,
Basic ORM strategy in PHP: How could it look like?
Using the SQLAlchemy ORM, I want to make sure values are the right type
The ORM in Django lets us easily annotate (add fields to) querysets based on
All my Doctrine2 setups are done within YAML files. I have an entity class
The SQLAlchemy ORM tutorial uses this class: >>> from sqlalchemy import Column, Integer, String
orm property name=poiLat ormtype=big_decimal notnull=true persistent=true precision=16 scale=14; property name=poiLong ormtype=big_decimal notnull=true persistent=true precision=16

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.