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 ...
- a clean zend f开发者_如何学运维ramework app generated with zend tool
- zend framework 1.10.7
- doctrine 2
- bootstrap.php - bootstrapping doctrine autoloaders, config & setup entity manager
- Application_Auth_Adapter - simply returns a very basic
Zend_Auth_Result
- IndexController
- indexAction - where i try to insert a new post
- loginAction - where i login with
Zend_Auth
- logoutAction - where i logout
- Application\Models\Post - the post model class
- Application\Models\User - the user model class
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)
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;
}
精彩评论