symfony - Symfony2 / Doctrine / Mapping Converter / Relationship / PK Strange Behavior -
after searching whole while decided show problem mapping converter implementation in symfony2. first, show setup:
the user tables having relationship:
-- ----------------------------------------------------- -- table `event_manager`.`user` -- ----------------------------------------------------- drop table if exists `event_manager`.`user` ; create table if not exists `event_manager`.`user` ( `id` int not null auto_increment , `email` varchar(255) null , `salt` varchar(255) null , `password` varchar(255) null , `logged_in` tinyint(1) null , `status` enum('active', 'inactive', 'deleted') null , primary key (`id`) , constraint `fk_user_user_data1` foreign key (`id` ) references `event_manager`.`user_data` (`user_id` ) on delete no action on update no action) engine = innodb; -- ----------------------------------------------------- -- table `event_manager`.`user_data` -- ----------------------------------------------------- drop table if exists `event_manager`.`user_data` ; create table if not exists `event_manager`.`user_data` ( `user_id` int not null , `image_id` int null , `gender` enum('male','female') null , `first_name` varchar(255) null , `last_name` varchar(255) null , `address` varchar(255) null , `zip` varchar(255) null , `city` varchar(255) null , `phone_private` varchar(255) null , `phone_mobile` varchar(255) null , `phone_work` varchar(255) null , `user_datacol` varchar(45) null , primary key (`user_id`) , constraint `fk_user_data_image1` foreign key (`image_id` ) references `event_manager`.`image` (`id` ) on delete no action on update no action) engine = innodb; create index `fk_user_data_image1_idx` on `event_manager`.`user_data` (`image_id` asc) ; with on db, use doctrine converter command:
php app/console doctrine:mapping:convert yml ./src/path-to-bundle/resources/config/doctrine --from-database --force --filter=user then result on user yaml:
user: type: entity table: user fields: email: type: string length: 255 fixed: false nullable: true salt: type: string length: 255 fixed: false nullable: true password: type: string length: 255 fixed: false nullable: true loggedin: type: boolean nullable: true column: logged_in status: type: string length: null fixed: false nullable: true manytomany: usergroup: targetentity: usergroup cascade: { } mappedby: null inversedby: user jointable: name: user_has_user_group joincolumns: - name: user_id referencedcolumnname: id inversejoincolumns: - name: user_group_id referencedcolumnname: id orderby: null onetoone: id: targetentity: userdata cascade: { } mappedby: null inversedby: null joincolumns: id: referencedcolumnname: user_id orphanremoval: false lifecyclecallbacks: { } as can see, doctrine removes "id" column primary key , uses instead name relationship brings me entity methods this:
/** * set id * * @param \parella\eventmanagerbundle\entity\userdata $id * @return user */ public function setid(\parella\eventmanagerbundle\entity\userdata $id = null) { $this->id = $id; return $this; } /** * id * * @return \parella\eventmanagerbundle\entity\userdata */ public function getid() { return $this->id; } this of course totally not want, , have create many entites @ once database, manually fixing not option. unfortunately have no idea if i'm causing problem or doctrine. miss something?
thanks responses.
copied comment here because confirmed actual problem.
doctrine not support single column being both primary id participating in owning relation. think it. should $user->getid() return? id or $userdata?
add user_data_id column user , put relation on it.
and edit yml files , use doctrine:schema:drop/update generate tables. let doctrine things it's way unless need maintain control.
Comments
Post a Comment