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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 12, 20262026-06-12T09:27:16+00:00 2026-06-12T09:27:16+00:00

I’m writing a Symfony2 app that allows mobile users to create and update Homes

  • 0

I’m writing a Symfony2 app that allows mobile users to create and update “Homes” via a REST service. I’m using MongoDB as the storage layer and Doctrine MongoDB ODM to do the Document handling.

The GET /homes/{key} and POST /homes methods are working fine. The problem comes when I attempt to update an existing Home with PUT /homes/{key}.

Here’s the current code:

/**
 * PUT /homes/{key}
 *
 * Updates an existing Home.
 *
 * @param Request $request
 * @param string $key
 * @return Response
 * @throws HttpException
 */
public function putHomeAction(Request $request, $key)
{
    // check that the home exists
    $home = $this->getRepository()->findOneBy(array('key' => (int) $key));

    // disallow create via PUT as we want to generate key ourselves
    if (!$home) {
        throw new HttpException(403, 'Home key: '.$key." doesn't exist, to create use POST /homes");
    }

    // create object graph from JSON string
    $updatedHome = $this->get('serializer')->deserialize(
        $request->getContent(), 'Acme\ApiBundle\Document\Home', 'json'
    );

    // replace existing Home with new data
    $dm = $this->get('doctrine.odm.mongodb.document_manager');
    $home = $dm->merge($updatedHome);
    $dm->flush();

    $view = View::create()
        ->setStatusCode(200)
        ->setData($home);

    $response = $this->get('fos_rest.view_handler')->handle($view);
    $response->setETag(md5($response->getContent()));
    $response->setLastModified($home->getUpdated());

    return $response;
}

The JSON string passed to the action is successfully deserialized to my Document object graph by JMSSerializer, but when I attempt the merge & flush, I get the error:

Notice: Undefined index:  in ..../vendor/doctrine/mongodb-odm/lib/Doctrine/ODM/MongoDB/Mapping/ClassMetadataInfo.php line 1265

I’ve been attempting to follow the documentation here: http://docs.doctrine-project.org/projects/doctrine-mongodb-odm/en/latest/reference/working-with-objects.html#merging-documents

Is there something I need to do to the deserialized Home before attempting to merge it? Is merge the wrong method?

Thanks.

  • 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-12T09:27:17+00:00Added an answer on June 12, 2026 at 9:27 am

    The only way I found to do this is to create a method in your document class that takes the updated document (e.g. $updatedHome) as a parameter and then just copies the required fields over into the existing document (e.g. $home).

    So above, the code:

    // replace existing Home with new data
    $dm = $this->get('doctrine.odm.mongodb.document_manager');
    $home = $dm->merge($updatedHome);
    $dm->flush();
    

    can be replaced with:

    // replace existing Home with new data
    $home->copyFromSibling($updatedHome);
    $this->getDocumentManager()->flush();
    

    and then it will work.

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

Sidebar

Related Questions

That's pretty much it. I'm using Nokogiri to scrape a web page what has
I'm parsing an RSS feed that has an ’ in it. SimpleXML turns this
We're building an app, our first using Rails 3, and we're having to build
I am writing an app with both english and french support. The app requests
I'm trying to create an if statement in PHP that prevents a single post
I am using Paperclip to handle profile photo uploads in my app. They upload
link Im having trouble converting the html entites into html characters, (&# 8217;) i
I have a string like this: La Torre Eiffel paragonata all’Everest What PHP function
I've got a string that has curly quotes in it. I'd like to replace
I am reading a book about Javascript and jQuery and using one of the

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.