Symfony2: spl_object_hash() expects parameter 1 to be object, string given in Doctrine Symfony2: spl_object_hash() expects parameter 1 to be object, string given in Doctrine symfony symfony

Symfony2: spl_object_hash() expects parameter 1 to be object, string given in Doctrine


I have finally found the problem:

When creating the object user, instead of setting those fields

$user->setDegree();$user->setWorkplace();  $user->setJobtype();$user->setResearchField();

as objects (because of the OneToMany relation), I gived here only a string, from the form.

So, for those fields, the code would be:

$degree     = $em->getRepository('SciForumVersion2Bundle:Degree')->findOneById($enquiry->getDegree());$workplace  = $em->getRepository('SciForumVersion2Bundle:Workplace')->findOneById($enquiry->getWorkplace());$job_type   = $em->getRepository('SciForumVersion2Bundle:JobType')->findOneById($enquiry->getJobtype());$research_field = $em->getRepository('SciForumVersion2Bundle:ResearchField')->findOneById($enquiry->getResearchField());

And then:

$user->setPerson($person);$user->setWorkplace($workplace);    $user->setJobtype($job_type);$user->setResearchField($research_field);

So: Be careful when you are getting this kind of warnings, you probably have to check if you are populating your object in the right way.