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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 28, 20262026-05-28T22:48:15+00:00 2026-05-28T22:48:15+00:00

I am trying to develop a friends system, and I need a Many-To-Many relation

  • 0

I am trying to develop a friends system, and I need a Many-To-Many relation on my User entities ; for now, this is what I’ve done :

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

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

But I would like to have some extra fields for these relations, for example the creation date or the state (accepted, pending, …) ; I’ve created another entity “Friend”, and I would like this entity to be used as a link between friends. But I don’t really know how to manage this…

Do you have some ideas ?

Thanks !

  • 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-28T22:48:16+00:00Added an answer on May 28, 2026 at 10:48 pm

    I’m afraid you need an extra class to make such an association.
    Here is the tip from doctrine documentation:

    Why are many-to-many associations less common? Because frequently you
    want to associate additional attributes with an association, in which
    case you introduce an association class. Consequently, the direct
    many-to-many association disappears and is replaced by
    one-to-many/many-to-one associations between the 3 participating
    classes.

    http://www.doctrine-project.org/docs/orm/2.1/en/reference/association-mapping.html#many-to-many-unidirectional

    I guess it should be Friend -> Special Association Class (with fileds: user_id, friend_id, date created) ->Friend.
    And you associate Friend to special class in two filed $myFriends and $imFriendOf 🙂

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

Sidebar

Related Questions

Im trying to develop a friends module to get more aquainted with django. Now
I am trying develop a basic referrer system to my Django website, system will
trying to develop web form using jquery. all i need is to have several
We are two friends trying to develop an application on local network using symfony
i am trying to develop a site where users can become friends of each
Trying to develop using MVVM: I have this Csla.PropertyStatus control that is created in
I'm trying to develop this code: $users = $facebook->api(array( 'method' => 'fql.query', 'query' =>
I am trying to develop a database for a website. This website has registered
Trying to develop a test app wherethe look is like ebook. user can flip
I am trying to develop a windows form application in which the user will

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.