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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 23, 20262026-05-23T12:01:46+00:00 2026-05-23T12:01:46+00:00

My problem is simple: I have Users and Stories in a many to many

  • 0

My problem is simple:

I have Users and Stories in a many to many relationship, I would like to store a couple of attribute in the UserStory relationship:

  • Priority (In order to set the ordering of the display for a given user)
  • Main (flags which one is the main story)

How can I do that ?

Let say we have the following :

<?php
/** @Entity */
class User
{
    // ...

    /**
     * @ManyToMany(targetEntity="Story", inversedBy="users")
     * @JoinTable(name="users_stories")
     */
    private $stories;

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

    // ...
}

/** @Entity */
class Story
{
    // ...
    /**
     * @ManyToMany(targetEntity="User", mappedBy="stories")
     */
    private $users;

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

    // ...
}
?>
  • 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-23T12:01:47+00:00Added an answer on May 23, 2026 at 12:01 pm

    As Crozin suggested, this question is a duplicate of:

    • Doctrine2: Best way to handle many-to-many with extra columns in reference table

    In my specific case the solution is simple. The Many-To-Many relationship needs to be build by hand, and extra fields need to be added manually. So two OneToMany relationship need to be build.

    So here are my 3 objects and the associated meta information for each attribute:

    <?php
    
    /**
     * @Entity
     * @Table(name="users")
     */
    
    class User{
    
        /**
         * @Id
         * @Column(type="integer", name="id")
         * @GeneratedValue(strategy="IDENTITY")
         */
        private $id;
    
        /**
         * @OneToMany(targetEntity="UserStory", mappedBy="user")
         */
        private $user_stories;
    
        // ...
    }
    
    
    /**
     * @Entity
     * @Table(name="user_stories")
     */
    
    class UserStory{
        /**
         * @Id
         * @Column(type="integer", name="id")
         * @GeneratedValue(strategy="IDENTITY")
         */
        private $id;
    
        /**
         * @ManyToOne(targetEntity="User", inversedBy="user_stories")
         */
        private $user;
    
        /**
         * @ManyToOne(targetEntity="Story", inversedBy="user_stories")
         */
        private $stories;
    
        /**
         * @Column(type="integer")
         */
        private $priority;
    
        /**
         * @Column(type="integer")
         */
        private $priority_tmp;
    
        /**
         * @Column(type="integer")
         */
        private $main;
    
        // ...
    }
    
    
    /**
     * @Entity
     * @Table(name="stories")
     */
    
    class Story
    {
        /**
         * @Id
         * @Column(type="integer", name="id")
         * @GeneratedValue(strategy="IDENTITY")
         */
        private $id;
    
        /**
         * @OneToMany(targetEntity="UserStory", mappedBy="stories")
         */
        private $user_stories;
    
        // ...
    }
    ?>
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have a simple problem. I have a path to a file in user
My problem is simple: I have a long list of elements that I want
I have a simple problem that i cannot solve. I have a dictionary: aa
My problem is quite simple: I have a 400MB file filled with 10,000,000 lines
I have a simple problem but I am not sure how to solve it.
I have a simple problem but no matter what I try I can't see
so I have a simple problem. I have a hover background image change effect,
I have a simple problem with XML got from database. Now, this XML can
I have a simple problem but I don't know how to solve it because
I have a simple problem . I am not able to figure out the

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.