php - Symfony2: Warning: spl_object_hash() expects parameter 1 to be object, integer given -



php - Symfony2: Warning: spl_object_hash() expects parameter 1 to be object, integer given -

i have many 1 relationship between entities project , course because each course of study can have many projects many projects related same course.

these entities:

class project{ /** * @orm\id * @orm\column(type="integer") * @orm\generatedvalue(strategy="auto") */ protected $id; //... other fields ... //----------------------- database relationship ----------------// //project-course - m:1 relationship /** * @orm\manytoone(targetentity="course", inversedby="project") * @orm\joincolumn(name="course_id", referencedcolumnname="id") **/ private $course;

and

class course{ /** * @orm\id * @orm\column(type="integer") * @orm\generatedvalue(strategy="auto") */ //... other fields ... //----------------------- database relationship----------------// //course-project 1:m relationship /** * @orm\onetomany(targetentity="project", mappedby="course") **/ private $project;

the error appears when seek insert new project course, form builder:

$builder ->add('name', 'text', array( 'attr' => array('class' => 'form-control'))) ->add('description', 'textarea', array( 'attr' => array('class' => 'form-control', 'rows' => '10'))) ->add('submit', 'submit', array( 'attr' => array('class' => 'btn btn-primary')));

i seek insert these info creating project object , filling result of form can see:

$project->setname($form->get('name')->getdata()); $project->setdescription($form->get('description')->getdata()); $project->setphasesnumber($form->get('phases_number')->getdata()); $project->setpathnumber($form->get('path_number')->getdata()); $project->setyear(date('y')); $project->setcourse(5); //number 5 test $em = $this->getdoctrine()->getmanager(); $em->persist($project); $em->flush();

the problem should related command $project->setcourse(5); , i've seen if remove relationship between project , course of study bug doesn't appear. bug disappears if comment line used set course of study id, think have problem relationship can't understand where.

i've read other question on stackoverflow doesn't help me.

thanks in advance.

its looking utilize object instance of course passing id of course of study not work.

you do:

//... $course = $this->getdoctrine()->getmanager()->getrepository('namespace:course')->findonebyid(5); $project->setcourse($course); //...

php symfony2 insert one-to-many

Comments

Popular posts from this blog

Delphi change the assembly code of a running process -

json - Hibernate and Jackson (java.lang.IllegalStateException: Cannot call sendError() after the response has been committed) -

C++ 11 "class" keyword -