Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 1027345
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 16, 20262026-05-16T12:13:36+00:00 2026-05-16T12:13:36+00:00

I have small problem when trying to create many-to-many link in doctrine. I have

  • 0

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.

$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();

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:

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;

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?

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-16T12:13:37+00:00Added an answer on May 16, 2026 at 12:13 pm

    Setting refClass is mandatory in many-to-many relationships

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have a small math problem I am trying to solve Given a number
I have a small problem with interfaces. Here it is in Pseudo code :
I have a small problem. I am trying to check to see if status's
I have small problem with my .net 2.0 winforms application. I want to embed
I have a small problem with a script. I want to have a default
I have a small problem with how should i think a... problem. I want
SQL to find duplicate entries (within a group) I have a small problem and
I'm having a small problem in Java. I have an interface called Modifiable. Objects
I am trying to create a wrapper on Linux which controls how many concurrent
I'm trying to develop a small application that tests how many requests per second

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.