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

  • Home
  • SEARCH
  • 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 6650605
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 26, 20262026-05-26T00:54:43+00:00 2026-05-26T00:54:43+00:00

I have the following db structure: User > UserRole < Role UserId UserRoleId RoleId

  • 0

I have the following db structure:

User     > UserRole      < Role
UserId     UserRoleId      RoleId
Name       UserId          Name
           RoleId
           Active
           CreationDate

And my doctrine2 classes are defined like this:

/**
 * @var Roles
 *
 * @ORM\ManyToMany(targetEntity="SecRole")
 * @ORM\JoinTable(name="SEC_USER_ROLE",
 *      joinColumns={@ORM\JoinColumn(name="SEC_USER_ID", referencedColumnName="SEC_USER_ID")},
 *      inverseJoinColumns={@ORM\JoinColumn(name="SEC_ROLE_ID", referencedColumnName="SEC_ROLE_ID")}
 *      )
 */
private $userRoles;

public function __construct() {
  parent::__construct();
  $this->userRoles = new \Doctrine\Common\Collections\ArrayCollection();
}

public function addSecRole(\myEntity\SecRole $role)
{
  $exists = $this->userRoles->exists(function($key, $elem) use($role) {
      return isset($elem) && $elem->getSecRoleCode() == $role->getSecRoleCode();
    });
  return !$exists && $this->userRoles->add($role);
}

To add a new role to the user, I do:

  $r = $rolerep->findOneBySecRoleCode('SystemAdmin');
  $u = $userrep->findOneByUserLogin('sysadmin');
  if (isset($r) && isset($u))
  {
    if ($u->addSecRole($r)) {
      $em->flush();
    }
  }

And everything works fine EXCEPT for one thing. The lifecycle events are not being called for SecUserRole entity!. And my suspicion is that since Doctrine is “adding” the new SecUserRole record for itself, then it doesn’t call the events for it.

I’m listening to prePersist, preUpdate, preDelete. Neither get the new record. I tried onFlush, but it seems it doesn’t get it either.

Is there something I’m missing, how could I solve this? doing the inserts by myself? Sure that’s a solution, but that leaves me to do also the queries myself, which is something I don’t want to do.

Well, thanks in advance
KAT LIM

  • 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-26T00:54:43+00:00Added an answer on May 26, 2026 at 12:54 am

    So far, haven’t found the best way BUT seems that Doctrine assumes that your Join Table will be “autogenerated” so it assumes that it doesn’t have nor need more than the two joining keys (UserId, RoleId).

    What I did to solve it was to stop using a ManyToMany, but use a OneToMany relationship to SecUserRole table. So inside the addSecRole method, I inserted the new object and then flushed the EM on the outside (like the example above).

    It seems that’s the best way I could do. I got the idea from this http://www.zendcasts.com/ where there is one cast specially for ManyToMany mappings.

    Well, hope this helps to all

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

Sidebar

Related Questions

I have the following class structure: class Organization { string Name; List<User> users; List<Organization>
As a veteran of mongodb, I have created the following structure: User: { name:
I have the following model structure class User(db.Model) : nickname = db.StringProperty(required=True) fullname =
I have an XML file with the following structure: <Products> <Product name=MyProduct1> <Components> <Component
I have following structure: class User < ActiveRecord::Base has_many :Hobbies, :dependent => :destroy accepts_nested_attributes_for
I have the following scenario- Pig version used 0.70 Sample HDFS directory structure: /user/training/test/20100810/<data
I have the following structure: TABLE: Field ID | Name ---|-------- 1 | Email
I have the following structure otsg > class > authentication.php > database.php > user.php
one more problem. I have following structure of XML: <player> <id>12</id> <name>pl_name</name> <experience> <points>147</points>
I have following db structure: File, User, FileRevision (has foreign key to File, and

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.