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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 23, 20262026-05-23T04:24:08+00:00 2026-05-23T04:24:08+00:00

I use the FOSUserBundle and in my User class I want two things: a

  • 0

I use the FOSUserBundle and in my User class I want two things:

  1. a user can invite another user for friendship. The friend has to confirm that friendship. Therefor a user has two attributes $inviteeForFriends and $invitedFriends which is a many2many self-referencing association to manage the pending friendships

  2. if a friendship is confirmed it is removed from the pendingfriendship assoc and added to the friendship assoc: $myFriends and $friendsWithMe which is a many2many self-referencing assoc, too.

Now in a controller I do this:

public function addAction() {
    $email = trim($this->get('request')->request->get("email"));
    // ...

    // find requested friend
    $userManager = $this->get('fos_user.user_manager');
    $friend = $userManager->findUserByEmail($email);
    // ...
    $user = $this->container->get('security.context')->getToken()->getUser();

    // ...

    // friend has not already asked the user
    if ($user->getInviteeForFriends()->contains($friend)) {
            throw new Exception(self::FRIEND_HAS_ALREADY_ASKED_MSG, self::FRIEND_HAS_ALREADY_ASKED);
    }
}

The $user->getInviteeForFriends()->contains($friend) in the end results in this error:

Notice: Undefined index: $invitedFriends in /home/r/workspace/MyProject/vendor/doctrine/lib/Doctrine/ORM/Persisters/BasicEntityPersister.php line 764

A echo get_class($user->getInviteeForFriends()) echos a Doctrine\ORM\PersistentCollection.
A echo $user->getInviteeForFriends()->count(); results in the same Undefined index error.

Those statements work:

$user->getMyFriends()->contains($friend)
$user->getInvitedFriends()->contains($friend)

but the $user->getInviteeForFriends()->contains($friend) does not. Why? What am I doing wrong?

This is a part of the User class:

/**
 * @ORM\Entity
 * @ORM\Table(name="fos_user")
 */
class User extends BaseUser
{
/**
 * @ORM\ManyToMany(targetEntity="User", mappedBy="myFriends")
 */
protected $friendsWithMe;

/**
 * @ORM\ManyToMany(targetEntity="User", inversedBy="friendsWithMe")
 * @ORM\JoinTable(name="friends",
 *     joinColumns={@ORM\JoinColumn(name="user_id", referencedColumnName="id")},
 *     inverseJoinColumns={@ORM\JoinColumn(name="friend_user_id", referencedColumnName="id")}
 * )
 */
protected $myFriends;


/**
 * I am invited for a friendship from these friends.
 * 
 * @ORM\ManyToMany(targetEntity="User", mappedBy="$invitedFriends")
 */
protected $inviteeForFriends;

/**
 * I invited those friends for a friendship.
 * 
 * @ORM\ManyToMany(targetEntity="User", inversedBy="$inviteeForFriends")
 * @ORM\JoinTable(name="pending_friendships",
 *     joinColumns={@ORM\JoinColumn(name="inviter_user_id", referencedColumnName="id")},
 *     inverseJoinColumns={@ORM\JoinColumn(name="invitee_user_id", referencedColumnName="id")}
 * )
 */
protected $invitedFriends;

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


/**
 * Add friendsWithMe
 *
 * @param MyProject\SiteBundle\Entity\User $friendsWithMe
 */
public function addFriendsWithMe(\MyProject\SiteBundle\Entity\User $friendsWithMe)
{
    $this->friendsWithMe[] = $friendsWithMe;
}

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

/**
 * Add myFriends
 *
 * @param MyProject\SiteBundle\Entity\User $myFriends
 */
public function addMyFriends(\MyProject\SiteBundle\Entity\User $myFriends)
{
    $this->myFriends[] = $myFriends;
}

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

/**
 * Add inviteeForFriend
 *
 * @param MyProject\SiteBundle\Entity\User $inviteeForFriend
 */
public function addInviteeForFriends(\MyProject\SiteBundle\Entity\User $inviteeForFriend)
{
    $this->inviteeForFriends[] = $inviteeForFriend;
}

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

/**
 * Add invitedFriend
 *
 * @param MyProject\SiteBundle\Entity\User $invitedFriend
 */
public function addInvitedFriends(\MyProject\SiteBundle\Entity\User $invitedFriend)
{
    $this->invitedFriends[] = $invitedFriend;
}

/**
 * Get invitedFriends
 *
 * @return Doctrine\Common\Collections\Collection $invitedFriends
 */
public function getInvitedFriends()
{
    return $this->invitedFriends;
}
}
  • 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-23T04:24:08+00:00Added an answer on May 23, 2026 at 4:24 am

    In the annotations $inviteeForFriends should be just inviteeForFriends. No dollar symbol there. It is never in annotations.

    Also see any examples from the doctrine orm 2.0 documentation:

    /** @Entity */
    class Feature
    {
        // ...
        /**
         * @ManyToOne(targetEntity="Product", inversedBy="features")
         * @JoinColumn(name="product_id", referencedColumnName="id")
         */
        private $product;
        // ...
    }
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

Hy guys, I decided to use FOSUserBundle for handling user authentication in my application.
Use case: user clicks the link on a webpage - boom! load of files
Use case: I've just entered insert mode, and typed some text. Now I want
Use Case When a user goes to my website, they will be confronted with
We use a data acquisition card to take readings from a device that increases
use case example I have a servlet that is receiving login requests. If a
use PHP and MySQL and want to use SELECT statement which date_post(datetime variable) start
Use: The user searches for a partial postcode such as 'RG20' which should then
Use case: we have some project meta-data files which we want tracked, but are
Use OPENXML to get dt element in MSSQL 2005. How can I get xmlns:dt

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.