PHP doctrine many-to-many last identifier problem

ivynicole97

New Member
I have small problem when trying to create many-to-many link in doctrine.I have simple scenario here: User and Role with many-to-many relationship defined.\[code\]$user = new User();$user->username = 'greg';$user->save();$role = new Role();$role->name = "Administrator";$role->save();$role_user = new Role_User();$role_user->Role = $role;$role_user->User = $user;$role_user->save();\[/code\]Now, I did some experiments and I can save user and role on it's own without any problems. They both have autoincrement ids and it works fine. The problem starts when I want to create relationship with exception saying 'Couldn't get last insert identifier'.I can't change DB schema and I was not generating it via YAML - I reverse engineered models from existing DB via 'generateModelsFromDb'. This is how this table looks like:\[code\]CREATE TABLE `ofp`.`Role_User` ( `roles_id` bigint(20) NOT NULL, `users_id` bigint(20) NOT NULL, KEY `FK8B6B91F429A30245` (`roles_id`), KEY `FK8B6B91F429A6266F` (`users_id`), CONSTRAINT `FK8B6B91F429A6266F` FOREIGN KEY (`users_id`) REFERENCES `User` (`id`), CONSTRAINT `FK8B6B91F429A30245` FOREIGN KEY (`roles_id`) REFERENCES `Role` (`id`) ) ENGINE=InnoDB DEFAULT CHARSET=latin1;\[/code\]Error I'm getting would suggest there is something wrong with creating primary key identifier to this table, but I'm not sure I need one there (Maybe unique key to eliminate duplicates?).Does anybody have any clues?
 
Back
Top