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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 27, 20262026-05-27T00:59:59+00:00 2026-05-27T00:59:59+00:00

Right now I’m using Doctrine2 in conjunction with Symfony2. I have an entity called

  • 0

Right now I’m using Doctrine2 in conjunction with Symfony2. I have an entity called “OrderRequest” with contains two references to another entry type called “OrderRequestPerson” (these are the orderer and receiver fields). In my form the user has the option to set the orderer = receiver or to fill out the receiver information.

I have a bug in this specific case: an order is placed where orderer = receiver, thus in the database the orderer and receiver fields have the same value (15 in this case, referring to the OrderRequestPerson id). If an admin goes and updates the order to where the orderer != receiver, I need to update the receiver field. Currently the entity manager will update the OrderRequestPerson with the id of 15, which consequently updates both the orderer and receiver. Is there a way I can tell Doctrine2 / Symfony2 to create a new entry for the receiver, with a new id and place the information into that entry rather than updating the orderer information?

My code is posted below:

    //  Get the entity manager.
    $em = $this->getDoctrine()->getEntityManager();

    //  Grab the order.
    $order = $em->getRepository('OrderRequestBundle:OrderRequest')
                ->getOrder($id);

    //  Get important information.
    $request = $this->getRequest();

    //  Create the OrderRequest form.
    $form = $this->get('form.factory')->create(new OrderRequestType(), $order);

    //  Fill the form with the request information.
    $form->bindRequest($request);

    //  Save the information.
    $em->flush();
  • 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-05-27T01:00:00+00:00Added an answer on May 27, 2026 at 1:00 am

    You basically have to detach the entity from the entity manager and then persist it again, which will force it to be inserted as a new one.

    $person = $order->getReceiver();
    $em->detach($person);
    $em->persist($person);
    $order->setReceiver($person);
    

    Now the problem is, you should only do that if the form is going to modify one or the other independently.

    I guess you could do it always before binding the form, and then if you see that both receiver and orderer contain the same data, you discard the receiver (don’t forget to remove or at least detach it from the $em), and set the orderer as the receiver again.

    I hope this makes sense. Be careful though otherwise you’ll end up with tons of duplicated and orphaned data in your db I think.

    You can read more on detach in the doctrine docs.

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

Sidebar

Related Questions

Right now, I have two Eclipse projects - they both use Maven 2 for
Right now, I have three models Post, Comment and User (using Devise ) associated
Right now, I have a domain entity named StyleBundle. This StyleBundle takes a list
Right now we have a dll file that contains all the database calls and
Right now I'm using the jQuery selector $('foo+bar') . Since I already have $('foo')
Right now I have a database (about 2-3 GB) in PostgreSQL, which serves as
Right now I have an SSIS package that runs every morning and gives me
Right now, I have code that looks something like this: Private Sub ShowReport(ByVal reportName
right now i have this <script type='text/javascript'> $(#beau).click(function(){ $(#beau).animate({margin-Top: 738px}, fast); }); </script> and
Right now any new UIViewController added to my storyboard needs to have a class

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.