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

  • Home
  • SEARCH
  • 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 6546661
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 25, 20262026-05-25T11:44:08+00:00 2026-05-25T11:44:08+00:00

I’m trying to do a simple ReferenceOne with MongoDB/Doctrine, but I get a really

  • 0

I’m trying to do a simple ReferenceOne with MongoDB/Doctrine, but I
get a really weird problem:

My ID:4e63611cbc347053a2000001
Create the Privilege Object
Check what's the Privilege->User Id
4e63611cbc347053a2000001
Persist it
Create the Event Object
Persist it
Check what's the Event->Privilege->User Id
4e63611cbc347053a2000001/OK/0
Flush it
Get my document id
4e6546d6bc34700605000012
Check what's the Event->Privilege->User Id
4e6546d6bc34700605000013/NOK/0

As you can see here, I create a Privilege Object where I reference a
User, I persist it => all ok. No I create a Event Object, I embed the
Privilege in it, check the id => all ok.

Now I flush it, and the user->id gets changed, I have no idea why this
happens.

I tried removing the cascade to see how it behaves and I just end up
with a null $id.

Any help would be welcome to understand what I’m doing wrong!

Here is the code I use:

echo "My ID:".$identity->getId()."<br />";
echo "Create the Privilege Object<br />";
$privilege = new \Entity\ODM\Event\Privilege();
$privilege->setUser($identity);
$privilege->setRole("admin");
echo "Check what's the Privilege->User Id<br />";
echo $privilege->getUser()->getId()."<br />";

echo "Persist it<br />";
$dm->persist($privilege);

echo "Create the Event Object<br />";
$event = new \Entity\ODM\Event();
$event->setName("My Event 222");
$event->setDate("25/08/2012");
$event->setUrl("myevent222");
$event->addPrivilege($privilege);
echo "Persist it<br />";
$dm->persist($event);

echo "Check what's the Event->Privilege->User Id<br />";
   $privs = $event->getPrivileges();

$output = $identity->getId();
$i = 0;
foreach($privs as $priv)
{
    if($priv->getUser()->getId() == '4e63611cbc347053a2000001')
        $output .= "/OK/".$i."<br />";
    else
        $output .= "/NOK/".$i."<br />";
    $i++;
    echo $output;
}

echo "Flush it<br />";
$dm->flush();
echo "Get my document id<br/>";
$id = $event->getId();
echo $id."<br/>";

$privs = null;
$priv = null;
echo "Check what's the Event->Privilege->User Id<br />";
   $privs = $event->getPrivileges();

$output = $identity->getId();
$i = 0;
foreach($privs as $priv)
{
    if($priv->getUser()->getId() == '4e63611cbc347053a2000001')
        $output .= "/OK/".$i."<br />";
    else
        $output .= "/NOK/".$i."<br />";
    $i++;
    echo $output;
}

Trimmed Entities:

class Event {
    /**
     * @Id
     */
    protected $id;

    /**
     * @EmbedMany(targetDocument="\Entity\ODM\Event\Privilege")
     */
    protected $privileges = array();
}

class Privilege {

/**
* @Id
*/
protected $id;

    /**
     * @ReferenceOne(targetDocument="\Entity\ODM\User",
cascade={"persist"})
     */
    protected $user;

/**
 * @param field_type $user
 */
public function setUser(\Entity\ODM\User $user) {
    $this->user = $user;
}
}
  • 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-25T11:44:09+00:00Added an answer on May 25, 2026 at 11:44 am

    For some reason the code here works perfectly fine under symfony2.

    The problem is coming from the way I implemented doctrine in Zend (modified Bisna) – Closing this question.

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

Sidebar

Related Questions

Basically, what I'm trying to create is a page of div tags, each has
Seemingly simple, but I cannot find anything relevant on the web. What is the
I'm trying to use string.replace('’','') to replace the dreaded weird single-quote character: ’ (aka
I'm trying to create an if statement in PHP that prevents a single post
I am trying to understand how to use SyndicationItem to display feed which is
link Im having trouble converting the html entites into html characters, (&# 8217;) i
I have just tried to save a simple *.rtf file with some websites and
I want to count how many characters a certain string has in PHP, but
I have a French site that I want to parse, but am running into
I am currently running into a problem where an element is coming back from

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.