php - Symfony2 ManyToMany or OneToMany or what? -
i'm trying since 2 weeks code running.
database structure (simplified):
table user | id | username |
table tasks | id | task title | task type |user
table task type | id | task type title |
table task done | id | task id | user id
what want:
add task, select if task global ( visible every user) or if task visible 1 user ( global or user-id put table field "user" in table "tasks".
if marked task "done", want make entry table "task done" task id , user id ( user id's value comes page, entry done, same value in table "tasks" field "user" , when task "global" task, value "user id" in table "task done" can't "global" id of user, working task.
i tried many ways many many, 1 many , on. errors, can me? have read, there problems table field names "id" field.
maybe can tell me how setup database structure / entites. me lot!
kind regards, marvin
edit 1
error while doing doctrine:schema:update --force in console.
[doctrine\dbaldbalexception] exception occurred while executing 'alter table tasks add constraint fk_50586597bf396750 foreign key (id) references task_done (id)': sqlstate[23000]: integrity constraint violation: 1452 cannot add or update child row: foreign key constraint fails (`seotool`.`#sql-382_38`, constraint `fk_50586597bf396750` foreign key (`id`) references `task_done` (`id`)) [pdoexception] sqlstate[23000]: integrity constraint violation: 1452 cannot add or update child row: foreign key constraint fails (`seotool`.`#sql-382_38`, constraint `fk_50586597bf396750` foreign key (`id`) references `task_done` (`id`))
code task.php
<?php namespace seotool\mainbundle\entity; use doctrine\common\collections\arraycollection; use symfony\component\validator\constraints assert; use doctrine\orm\mapping orm; /** * @orm\entity * @orm\table(name="tasks") */ class task { /** * @orm\column(type="integer") * @orm\id * @orm\generatedvalue(strategy="auto") */ protected $id; /** * @orm\column(type="string") */ protected $task_title; /** * @orm\column(type="text") */ protected $task_description; /** * @orm\column(type="string") */ protected $task_priority; /** * @orm\manytoone(targetentity="tasktypes", inversedby="task") * @orm\joincolumn(name="tasktype", referencedcolumnname="id") */ protected $tasktypes; /** * @orm\manytoone(targetentity="user", inversedby="task") * @orm\joincolumn(name="user", referencedcolumnname="id") */ protected $user; /** * @orm\manytoone(targetentity="taskdone", inversedby="task") * @orm\joincolumn(name="id", referencedcolumnname="id") */ protected $taskdone; ....
code taskdone.php
<?php namespace seotool\mainbundle\entity; use doctrine\common\collections\arraycollection; use doctrine\orm\mapping orm; /** * @orm\entity * @orm\table(name="task_done") */ class taskdone { /** * @orm\onetomany(targetentity="task", mappedby="taskdone") */ protected $task; /** * @orm\column(type="integer") * @orm\id * @orm\generatedvalue(strategy="auto") */ private $id; .....
i couldn´t recreate exact error looking @ disired table structure got example running changing name of join column... asking doctrine create column used foreing key table contains column named id. use name="task_ id" instead.
you have this:
/** * @orm\manytoone(targetentity="taskdone", inversedby="task") * @orm\joincolumn(name="id", referencedcolumnname="id") */ protected $taskdone;
change this:
/** * @orm\manytoone(targetentity="taskdone", inversedby="task") * @orm\joincolumn(name="task_id", referencedcolumnname="id") */ protected $taskdone;
you have relation backwards. create filed task_id in "task" table , wanted create in "task done" table. fix should place onetomany on task entity , manytoone in taskdone.
Comments
Post a Comment