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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 15, 20262026-06-15T17:31:42+00:00 2026-06-15T17:31:42+00:00

Error occurs when attempting to persist a one-to-many relationship. In particular, a client may

  • 0

Error occurs when attempting to persist a one-to-many relationship. In particular, a client may have multiple household members; a given household member is associated with one and only one client. [I am new to Symfony so errors are expected!] Your guidance gratefully accepted.

N.B. Alternate controller snippet below yields integrity constraint error by trying to set the client’s id in the household table to null.

Clients Entity snippet

namespace Mana\AdminBundle\Entity;

use Doctrine\ORM\Mapping as ORM;
use Doctrine\Common\Collections\ArrayCollection;

/**
 * Mana\AdminBundle\Entity\Clients
 *
 * @ORM\Table(name="clients")
 * @ORM\Entity
 */
class Clients
{
    protected $members;

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

    public function getMembers()
    {
        return $this->members;
    }

    public function setMembers(ArrayCollection $members)
    {
        $this->members = $members;
    }

    /**
     * @var integer $id
     *
     * @ORM\Column(name="id", type="integer", nullable=false)
     * @ORM\Id
     * @ORM\GeneratedValue(strategy="IDENTITY")
     * @ORM\OneToMany(targetEntity="Household", mappedBy="clients")
     * @ORM\ManyToOne(targetEntity="EthDesc", inversedBy="clients")
     * @ORM\JoinColumn(name="eid", referencedColumnName="id")
     */

Household Entity snippet

namespace Mana\AdminBundle\Entity;

use Doctrine\ORM\Mapping as ORM;

/**
 * Mana\AdminBundle\Entity\Household
 *
 * @ORM\Table(name="household")
 * @ORM\Entity(repositoryClass="Mana\AdminBundle\Entity\HouseholdRepository")
 */
class Household {

    /**
     * @var integer $hid
     *
     * @ORM\Column(name="hid", type="integer", nullable=false)
     * @ORM\Id
     * @ORM\GeneratedValue(strategy="IDENTITY")
     * @ORM\ManyToOne(targetEntity="Clients", inversedBy="members")
     * @ORM\JoinColumn(name="cid", referencedColumnName="id")
     * @ORM\ManyToOne(targetEntity="EthDesc", inversedBy="members")
     * @ORM\JoinColumn(name="eid", referencedColumnName="id")
     */

ClientsType snippet

    ->add('members', 'collection', array(
        'type' => new HouseholdType(),
        'allow_add' => true, 
        'by_reference' => false,
        'cascade_validation'  => true,
        ));

Controller snippet

public function createAction(Request $request) {
    $entity = new Clients();
    $form = $this->createForm(new ClientsType(), $entity);
    $form->bind($request);

    if ($form->isValid()) {
        $em = $this->getDoctrine()->getManager();
        $em->persist($entity);
        $em->persist($entity->getMembers());
        $em->flush();
        return $this->redirect($this->generateUrl('clients_show', array('id' => $entity->getId())));
    }
}

Alternate controller snippet

public function createAction(Request $request) {
    $entity = new Clients();
    $form = $this->createForm(new ClientsType(), $entity);
    $form->bind($request);

    if ($form->isValid()) {
        $em = $this->getDoctrine()->getManager();
        $em->persist($entity);
        foreach ($entity->getMembers() as $member)
        {
            $em->persist($member);
        }
        $em->flush();
        return $this->redirect($this->generateUrl('clients_show', array('id' => $entity->getId())));
    }
  • 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-15T17:31:42+00:00Added an answer on June 15, 2026 at 5:31 pm

    The times I have gotten this to work, I did not

    use Doctrine\Common\Collections\ArrayCollection; 
    

    I just

    $this->field = new \Doctrine\Common\Collections\ArrayCollection();
    

    in my constructor.

    Also, you may want to consider adding Household (which appear to be the members in clients) as an entity form:

    ->add('members', 'entity', array(
        'type' => new HouseholdType(),
        'allow_add' => true, 
        'by_reference' => false,
        ));
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

Is connecting with one IP but an error occurs with a complete strange host/ip??
What is the best workflow taken when connection error occurs. Let say we have
The error occurs when attempting to extend Unit with County, specifically, when restarting the
I'm attempting to help a client who is getting a ClassFormatError. The error message
I have an error message that occurs every time I use SQL Server 2012
I have this error when building and running my project in xCode: RootViewController may
While attempting to cross-compile ICU using android-ndk-r7 in Linux, the following error occurs after
The error occurs when I try to do this friend std::ostream& operator<<(std::ostream& os, const
This is the error occurs in logcat,can anyone tell what's the meaning? private int
I do not understand why this error occurs...Is this a bug in XE, or

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.