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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 30, 20262026-05-30T00:30:28+00:00 2026-05-30T00:30:28+00:00

Using Symfony2 and Doctrine ODM with MongoDB, I need to access the parent document

  • 0

Using Symfony2 and Doctrine ODM with MongoDB, I need to access the parent document from within an embedded document.

I have a ‘Cardset’ object which has embedMany on ‘Card’ objects.

The ‘Card’ object has a ‘save image’ method and I want that to use the ID of the Cardset object that contains it as part of the path to which it saves.

I can’t find a way to access the parent document from within the embeddeddocument.

If I could get hold of an instance of ‘DocumentManager’, I might be able to use the ‘getParentAssociation()’ method. But this

$this->get('doctrine.odm.mongodb.document_manager');

doesn’t work since it’s not inside a Controller. I’m not experienced enough to know how to make the DocumentManager into a service that would be available from inside my object class.

Can anyone help?

  • 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-30T00:30:29+00:00Added an answer on May 30, 2026 at 12:30 am

    You theorically can access this using the UnitOfWork:

    $uo = $this->get('doctrine.odm.mongodb.document_manager')->getUnitOfWork();
    list($mapping, $parent, $propertyPath) = $uo->getParentAssociation($embeddedDocument); 
    

    EDIT: You should’nt get it from your entities/documents (or embedded documents).
    But if you want to, you will have to inject it using a listener on “postLoad”: http://readthedocs.org/docs/doctrine-mongodb-odm/en/latest/reference/events.html?highlight=postload#lifecycle-events

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

Sidebar

Related Questions

I have a join-table which is created by using @ORM\ManyToMany annotation in Symfony2/Doctrine. It
I am trying to fetch an object from my database in symfony2 and doctrine
I'm using Doctrine MongoDB ODM with Symfony 2.0.5 This code causes no effect: $dm
We are using Symfony2's roles feature to restrict users' access to certain parts of
I am using Doctrine with Symfony2. My config.yml file looks something like this:- Doctrine
Using Symfony and Doctrine, I have a multi-select list box. The multiple default values
I am using Symfony 2 with Doctrine 2. I have a UserListener ( symfony
I'm using Symfony and Doctrine, and have several many-to-many relations that work fine. But
I am using Symfony 2.0.10 with Doctrine 2.1 and have rather simple query (see
I have a project created using Symfony 1.4.15. Because I like Doctrine :) I

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.