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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 7, 20262026-06-07T03:48:47+00:00 2026-06-07T03:48:47+00:00

I find the documentation very poor when it comes to explaining the creation of

  • 0

I find the documentation very poor when it comes to explaining the creation of relationships between entities. So, i’ll have to ask for help to my fellow StackExchangers. So, i’m trying to build the following cases:

Case 1

A User belongs to one or more Group, and a Group can have many Permission. A User also can have a Permission.

Case 2

A Ticket has a Category, multiple Tag and multiple Comment.

Thanks in advance!

  • 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-07T03:48:48+00:00Added an answer on June 7, 2026 at 3:48 am

    Sure thing. First thing to understand is that there is no “one way” to do this. Doctrine gives a lot of flexibility in terms of how you define the relationship – even if multiple definitions produce the exact same DDL (and this is important to understand – some of the mapping choices only effect the object-side of the ORM, not the model-side)

    Here’s your Users/Groups/Permissions example, which are actually all many-to-many associations (I excluded all non-relevant but required code, like PK column definition)

    <?php
    
    namespace Your\Bundle\Entity;
    
    use Doctrine\ORM\Mapping as ORM;
    use Doctrine\Common\Collections\ArrayCollection;
    
    /**
     * @ORM\Entity
     */
    class User
    {
      /**
       * Many-To-Many, Unidirectional
       *
       * @var ArrayCollection $groups
       *
       * @ORM\ManyToMany(targetEntity="Group")
       * @ORM\JoinTable(name="user_has_group",
       *      joinColumns={@ORM\JoinColumn(name="user_id", referencedColumnName="id")},
       *      inverseJoinColumns={@ORM\JoinColumn(name="group_id", referencedColumnName="id")}
       * )
       */
      protected $groups;
    
      /**
       * Many-To-Many, Unidirectional
       *
       * @var ArrayCollection $permissions
       *
       * @ORM\ManyToMany(targetEntity="Permission")
       * @ORM\JoinTable(name="user_has_permission",
       *      joinColumns={@ORM\JoinColumn(name="user_id", referencedColumnName="id")},
       *      inverseJoinColumns={@ORM\JoinColumn(name="permission_id", referencedColumnName="id")}
       * )
       */
      protected $permissions;
    
      public function __construct()
      {
        $this->groups = new ArrayCollection();
        $this->permissions = new ArrayCollection();
      }
    }
    
    /**
     * @ORM\Entity
     */
    class Group
    {
      /**
       * Many-To-Many, Unidirectional
       *
       * @var ArrayCollection $permissions
       *
       * @ORM\ManyToMany(targetEntity="Permission")
       * @ORM\JoinTable(name="group_has_permission",
       *      joinColumns={@ORM\JoinColumn(name="group_id", referencedColumnName="id")},
       *      inverseJoinColumns={@ORM\JoinColumn(name="permission_id", referencedColumnName="id")}
       * )
       */
      protected $permissions;
    
      public function __construct()
      {
        $this->permissions = new ArrayCollection();
      }
    }
    
    /**
     * @ORM\Entity
     */
    class Permission {}
    

    If you have questions about what’s going on here, let me know.

    Now, to your second example

    <?php
    
    namespace Your\Bundle\Entity;
    
    use Doctrine\ORM\Mapping as ORM;
    use Doctrine\Common\Collections\ArrayCollection;
    
    /**
     * @ORM\Entity
     */
    class Ticket
    {
      /**
       * Many-To-One, Unidirectional
       *
       * @var Category
       *
       * @ORM\ManyToOne(targetEntity="Category")
       * @ORM\JoinColumn(name="category_id", referencedColumnName="id")
       */
      protected $category;
    
      /**
       * Many-To-Many, Unidirectional
       *
       * @var ArrayCollection $permissions
       *
       * @ORM\ManyToMany(targetEntity="Tag")
       * @ORM\JoinTable(name="tickt_has_tag",
       *      joinColumns={@ORM\JoinColumn(name="ticket_id", referencedColumnName="id")},
       *      inverseJoinColumns={@ORM\JoinColumn(name="tag_id", referencedColumnName="id")}
       * )
       */
      protected $tags;
    
      /**
       * One-To-Many, Bidirectional
       *
       * @var ArrayCollection $comments
       *
       * @ORM\OneToMany(targetEntity="Comment", mappedBy="ticket")
       */
      protected $comments;
    
      public function __construct()
      {
        $this->tags = new ArrayCollection();
        $this->comments = new ArrayCollection();
      }
    }
    
    /**
     * @ORM\Entity
     */
    class Comment
    {
      /**
       * Many-To-One, Bidirectional
       *
       * @var Ticket $ticket
       *
       * @ORM\ManyToOne(targetEntity="Ticket")
       * @ORM\JoinColumn(name="ticket_id", referencedColumnName="id")
       */
      protected $ticket=null;
    }
    
    /**
     * @ORM\Entity
     */
    class Tag {}
    
    /**
     * @ORM\Entity
     */
    class Category {}
    

    As before, let me know if you want any of this explained.

    P.S. None of this was actually tested, I just kinda banged it out in my IDE real fast. There might be a typo or two 😉

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

Sidebar

Related Questions

I have maybe very very Simple Question: Where i can find documentation about expressions
How should Java's drawImage() be used? I do not find the JDK documentation very
The problem? I look up stuff in the xcode documentation and find very useful
This must be very simple, but I couldn't find it on the documentation. In
I have been looking online to find documentation for the function in QTP and
Due to Umbraco documentation being very.... how should I say.. 'loose'? and split between
I have just started using NSIS . It works very well but I find
It's a pretty straightforward question but I can't find very good documentation on the
I find the documentation on NSThread not very informative for newcomers in NSThread and
Can you help me solve this problem? I've not managed to find any documentation

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.