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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 7, 20262026-06-07T21:37:00+00:00 2026-06-07T21:37:00+00:00

I have this scenario I have four classes User profiles Activity Workbook user can

  • 0

I have this scenario

I have four classes

User
profiles
Activity
Workbook

user can have many profiles based on per year. Every year diff profile
User profile will have many to many with Activities

so there will be profile_activities table with profile_id and activity_id

Now User will do 1 workbook per activity per profile

so i am confused how to map in database

I mean for profile table , i can have

class profile


@many to many
protected $activities

many to one
protected $user

But in class workbook how to define foreign key which belongs to activity and profile relationship table

For every activity child has to complete workbook. How should i define that

@[one to one [PK of activity_profile table]

protected $workbook

  • 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-07T21:37:02+00:00Added an answer on June 7, 2026 at 9:37 pm

    Symfony provides you different methods for do this operation.
    One of those methods is annotation. With annotation you can write directly into php classes this relationships and more (like db column’s type, specify if an attribute is mandatory and so on …)

    So, let’s took this example (because i dind’t understand the relationships of your entities)
    Consider two entities: User and Groups.
    One user can belong to n Groups and a Groups can have m Users. This mean that we have to “break up” m-n cardinality into an m-1-n relationship.
    In symfony (with doctrine; i don’t know if with mongodb and similar is the same) you haven’t to create this “intermediate table” as a php class. All you have to do is, with annotation into php classes involves, specify what tables are related and in what way.
    Let’s see how!

    /**
     * Acme\UserBundle\Entity\User
     *
     * @ORM\Table(name="users")
     * @ORM\Entity()
     */
    class User implements AdvancedUserInterface
    {
        /**
         * @ORM\Column(type="integer")
         * @ORM\Id
         * @ORM\GeneratedValue(strategy="AUTO")
         */
        private $id;
    [...]
       /**
         * @ORM\ManyToMany(targetEntity="Groups", inversedBy="users")
         *
         */
        private $groups;
    [...]
    

    }

    As you can see, this is a part of a php class mapped into db table with doctrine (ORM).
    This class han an attribute $groups that tells (take a look to annotations) that is a many-to-many relationship between this class and another class (identified by targetEntity) and inversedBy tells what attribute (db column; attribute if you talk about class) is involved into the relationship (external key).

    /**
     * @ORM\Table(name="groups")
     * @ORM\Entity()
     */
    class Groups implements RoleInterface
    {
        /**
         * @ORM\Column(name="id", type="integer")
         * @ORM\Id()
         * @ORM\GeneratedValue(strategy="AUTO")
         */
        private $id;
    [...]
        /**
         * @ORM\ManyToMany(targetEntity="User", mappedBy="groups")
         */
        private $users;
    [...]
    }
    

    This entity is group entity and have the “other side” of relationship: $user
    As you can see, there is @ORM\ManyToMany(targetEntity="User", mappedBy="groups") that indicates that realtionship is with class User and field into User class is groups.

    Now you can run doctrine command for entity generation onto db php app/console doctrine:generate:entities Acme where Acme is bundle’s name and the trick is done.

    Some words on mappedBy and inversedBy:

    • There are “two” sides: the inverted side and the owning side. Remember that docrine will “observe” changes only into the owning side, so take care to place it into the right class
    • The inversed side is identified by mappedBy keyword and it’s value is the name of owning side class
    • The owning side is identified with inversedBy keyword and it’s value is the name of the inversed side class
    • manyToOne association has always the owning side
    • oneToMany association has always the inversed side
    • The owning side of oneToOne relationship is always the entity with external key
    • Into manyToMany relationship is the same
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have this scenario. I want group on Country and Category. A store can
Consider this scenario; suppose I have WPF window which have four objects bonded to
I have been given a task that can be simplified to this scenario: Customers
Say we have this scenario: Artist ==< Album ==< Track //ie, One Artist can
I have this scenario well, i'll let the model explain. public class ScheduleMonthlyPerDayModel {
I have this scenario where I would like to redirect my domains using the
So I have this scenario <div id=editor contenteditable=true> <div id=list>Hello</div> </div> I want to
In my app, I have this scenario where I need to post an object
Imagine this scenario: You have a desktop and a laptop. The desktop has a
Consider this scenario. I have my own website, that I use as my identifier,

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.