Doctrine 2 – Unable to access newly created record (outside of Doctrine)

A few key notes on my environment:

  • I have an app that is built on WordPress and we’re using Doctrine as our ORM.
  • In order to maintain WP’s integrity, we let WP handle the creation of users
  • Every WP object and custom object is mapped properly through Doctrine.

The situation is:

Read More
// 1. Create a user via **WP** function (which returns ID)
$wp_user_id = wp_insert_user($wp_user_array);

// 2. Then, I need to immediately retrieve that user object via Doctrine
$wp_user = $MyDb->em->getRepository('WpUsers')->findOneBy(array('id'=>$wp_user_id));

// 3. RESULT = NULL

The object is not found, presumably because the Entity is cached or stored in memory somewhere by Doctrine.

How can I force Doctrine to go look at the DB and get this newly created user?

Related posts

2 comments

  1. The solution for this ended up being fairly simple. After trying clear(), refresh() and force clearing Doctrine’s cache I was running out of options.

    It turns out what I had to do to get Doctrine to check that the new record was created, is close and open the connection:

    $this->_em->getConnection()->close();
    $this->_em->getConnection()->connect();
    

    Not the most ideal solution, I know, but it works and I have been debugging this for five days now!

Comments are closed.