views:

63

answers:

1

i am having problems persisting a Doctrine 2 entity (Post) when the User is logged in with Zend_Auth.

i am quite sure its the login as the code runs, when the user is logged out, and fails once the user is logged in. and it seems that the identity returned from the Zend_Auth::authenticate() plays a role in affecting the error message.

ok my setup is as follows ...

when i return stdClass in authenticate() i will get an error message like

A new entity was found through a relationship that was not configured to cascade persist operations: stdClass@000000006ba9d6930000000007857036. Explicitly persist the new entity or configure cascading persist operations on the relationship.

return new Zend_Auth_Result(Zend_Auth_Result::SUCCESS, new StdClass);

when i return a string, the error i get,

A new entity was found through a relationship that was not configured to cascade persist operations: @. Explicitly persist the new entity or configure cascading persist operations on the relationship.

when i return a Application\Models\Post, i get

A new entity was found through a relationship that was not configured to cascade persist operations: Application\Models\User@000000000aea1b5f0000000028c32e2c. Explicitly persist the new entity or configure cascading persist operations on the relationship.

how can i proceed from here? how do i debug this?

for those who like to see a video of it in action (the error), i have it on screenr and youtube (with annotations)

A: 

i finally found the answer whith the help from doctrine users - google groups

it lies in my mistake of setting the post's user to the logged in user in prePersist

// prePersist
...
// set user
$auth = \Zend_Auth::getInstance();
if ($auth->hasIdentity()) {
    $user = $auth->getIdentity();
    $this->user = $user;
}
jiewmeng