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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 4, 20262026-06-04T07:16:49+00:00 2026-06-04T07:16:49+00:00

A Product may have zero or more Label . A Label can be assigned

  • 0

A Product may have zero or more Label. A Label can be assigned to zero or more Product. So, what’s the difference between mapping A and mapping B in Doctrine?

Mapping A (OneToMany – ManyToOne)

/**
 * @ORM\Entity
 * @ORM\Table(name="product")
 */
class Product
{
    /**
     * @ORM\OneToMany(targetEntity="Label", mappedBy="products")
     */
    protected $labels;
}

/**
 * @ORM\Entity
 * @ORM\Table(name="label")
 */
class Label
{
    /**
     * @ORM\ManyToMany(targetEntity="Product", inversedBy="labels")
     */
    protected $products;
}

Mapping B (ManyToMany – ManyToMany) documentation example

/**
 * @ORM\Entity
 * @ORM\Table(name="product")
 */
class Product
{
    /**
     * @ORM\ManyToMany(targetEntity="Label", mappedBy="products")
     */
    protected $labels;
}

/**
 * @ORM\Entity
 * @ORM\Table(name="label")
 */
class Label
{
    /**
     * @ORM\ManyToMany(targetEntity="Product", inversedBy="labels")
     */
    protected $products;
}
  • 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-04T07:16:51+00:00Added an answer on June 4, 2026 at 7:16 am

    Your first example you try to match a ONE-TO-MANY relation to a MANY-TO-MANY relation. This will cause problems when trying to access the labels of a product. It will try to find the relation in a column in the label table. While a many-to-many relation should have an extra table that couples the two entities.

    This is pure theoretically. I didn’t try it with real code, but I suppose Doctrine will throw an exception if you use the first example. I fact the first example should not be used.

    If you’re not familiair with different types of relations read some articles about RDBMS:
    http://en.wikipedia.org/wiki/Relational_model

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

Sidebar

Related Questions

Building a commercial product may use various open source libraries that have use of
We're working on a product that may or may not have differing license schema
I have a table Orders. Each order can have the same product multiple times.
I'm working on a web product that may be hosted as an intranet site.
String product = Integer.toString(w); char[] original = String.toCharArray(product); This is the code I have
The product I have been working on has been in development for the past
One of the columns in my table is DataSource. Datasource can have two values,
I have this string String str=lookup('PRODUCT','LKP1','LKP_TAB1.ID')||('A'='B')-lookup('PRODUCT','LKP2','LKP_TAB1.ID')||'CON.ID' This is just one example, in practical situation
My company is making a product where we have both a front and backend.
Suppose I have a composite class PharmaProduct (which represents the product hierarchy of a

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.