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 8425265
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 10, 20262026-06-10T04:13:23+00:00 2026-06-10T04:13:23+00:00

ive been trying to figure this out for 2 hours now and i cant

  • 0

ive been trying to figure this out for 2 hours now and i cant seem to understand what went wrong.

I am using Symfony2 and FOSUserBundle.

I created a User entity which extends FOSUserBundle’s BaseUser class. Within this User entity, i have 3 variables, id, my_mentors and my_mentees. More details are below:

class User extends BaseUser
{
/**
 * @ORM\Id
 * @ORM\Column(type="integer")
 * @ORM\GeneratedValue(strategy="AUTO")
 */
protected $id;                

/**
 * @ORM\ManyToMany(targetEntity="User", mappedBy="my_mentees")
 */
protected $my_mentors;

/**
 * @ORM\ManyToMany(targetEntity="User", inversedBy="my_mentors")
 * @ORM\JoinTable(name="mentor_and_mentee_relationship",
 *      joinColumns={@ORM\JoinColumn(name="user_id", referencedColumnName="id")},
 *      inverseJoinColumns={@ORM\JoinColumn(name="mentors_or_mentees_user_id", referencedColumnName="id")}
 *      )
 */
protected $my_mentees;

public function __construct()
{
    parent::__construct();
    $this->my_mentors = new ArrayCollection();
    $this->my_mentees = new ArrayCollection();
}

public function __toString()
{
    return $this->getUsername();
}

/**
 * Get id
 *
 * @return integer 
 */
public function getId()
{
    return $this->id;
}    

/**
 * Add my_mentors
 *
 * @param Fitness\FitBundle\Entity\User $myMentors
 */
public function addUser(\Fitness\FitBundle\Entity\User $myMentors)
{
    $this->my_mentors[] = $myMentors;
}

/**
 * Get my_mentors
 *
 * @return Doctrine\Common\Collections\Collection 
 */
public function getMyMentors()
{
    return $this->my_mentors;
}

/**
 * Get my_mentees
 *
 * @return Doctrine\Common\Collections\Collection 
 */
public function getMyMentees()
{
    return $this->my_mentees;
}
}

I created the self reference because a Mentee(which is a User) will subscribe to a Mentor(which is also a User). I tried to do this using the following function:

public function subscribeAction($menteeID, $mentorID)
{                
    $em = $this->getDoctrine()
               ->getEntityManager();

    $mentor = $em->getRepository('TestBundle:User')
                ->find($mentorID);
    $mentee = $em->getRepository('TestBundle:User')
                ->find($menteeID);                

    $currentMentors = $mentee->getMyMentors();
    if ($currentMentors->contains($mentor))
        $this->get('session')->setFlash('subscribe-notice', 'You have already signed up to this mentor!');
    else
    {
        $mentee->setIsMentor(false);
        $mentee->addUser($mentor);
        $mentor->addUser($mentee);
        $em->persist($mentee);
        $em->persist($mentor);
        $em->flush();            
        $this->get('session')->setFlash('subscribe-notice', 'Subscription succesful!');
    }

    return $this->redirect($this->generateUrl('TestBundle_testpage', array('id' => $mentor->getMentorProfile()->getId()) ));
}

The problem here is that when i check the database, it does not persist the data. The mentor-mentee relationship information is not stored in the table “mentor_and_mentee_relationship” as declared by the annotation.

I persisted both $mentor and $mentee in an attempt to get it to work, but apparently it doesnt.

Could my ORM annotation be declared wrongly?

  • 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-06-10T04:13:25+00:00Added an answer on June 10, 2026 at 4:13 am

    You are using the same function (addUser) to add a mentor and to add a mentee. This is wrong. First you need two different setters in your entity (I changed the name of addUser to make it clear)

    /**
     * Add my_mentors
     *
     * @param Fitness\FitBundle\Entity\User $myMentors
     */
    public function addMentor(\Fitness\FitBundle\Entity\User $myMentors)
    {
        $this->my_mentors[] = $myMentors;
    }
    
    /**
     * Add my_mentees
     *
     * @param Fitness\FitBundle\Entity\User $myMentees
     */
    public function addMentee(\Fitness\FitBundle\Entity\User $myMentees)
    {
        $this->my_mentees[] = $myMentees;
    }
    

    Then in your controller do:

            $mentee->addMentor($mentor);
            $mentor->addMentee($mentee);
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I've been trying to figure this out now for a few hours and its
I've been trying to figure this out for hours now, and I'm at my
I've been trying to figure this out for a few hours now. In order
I've been trying to figure this out for hours, so thought I should ask
I've been trying to figure this out and can't seem to get it. Here
I've been trying to figure this one out for a bit using patterns or
I've been trying for a while now to figure this out but my lack
I've been trying to figure this issue out for about an hour now. I've
I have been banging my head for hours trying to figure out why this
I've been trying to figure it out for hours and i didn't success, This

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.