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

后端 未结 1 1698
慢半拍i
慢半拍i 2020-12-31 00:36

I am trying to populate the database with the object User and Person by executing

persist and flush.

First of all, I am creating the Person object and persis

相关标签:
1条回答
  • 2020-12-31 01:04

    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.

    0 讨论(0)
提交回复
热议问题