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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 12, 20262026-06-12T23:10:30+00:00 2026-06-12T23:10:30+00:00

I joust started playing around with Doctrine ORM library, and Im learning about all

  • 0

I joust started playing around with Doctrine ORM library, and Im learning about all associations between tables.

So Im stuck with differences in Unidirectional and Bidirectional relation.

As I get it, Unidirectional relation has primary key only on one side, and that side is owning side right?
And Bidirectional relation have primary key in both tables and therefore you can have relation from both sides, and set constrains on both sides.

Now, Im reading through Doctrine documentation about relations and there you have:
Unidirectional and Bidirectional associations.

But they produce the same SQL, and the same tables with the same primary key-s and constrains. So I dont really see any difference in those two. And both examples have primary key on one side.

As I get it the true Bidirectional relation should have primary keys in both tables pointing to the other table right? And with given example on Doctrine documentation that is not the case. Both examples give the same result and are the same.

So what I did, is this, lets say I have User and Card Entity, and want relation to be OneToOne Bidirectional.

    /**
 * @Entity
 * @Table(name="users")
 */

class User
{
    /**
     * @Id
     * @GeneratedValue
     * @Column(type="bigint")
     */
    protected $id;

    /**
     * @OneToOne(targetEntity="Card", mappedBy="User")
     * @JoinColumn(name="card_id", referencedColumnName="id")
     */
    protected $card;

    /**
     * @Column(name="user_name", type="string")
     */
    protected $userName;

    /**
     * @Column(name="user_pass", type="string")
     */
    protected $userPass;
}

    /**
 * @Entity
 * @Table(name="cards")
 */

class Card
{
    /**
     * @Id
     * @GeneratedValue
     * @Column(type="bigint")
     */
    protected $id;

    /**
     * @OneToOne(targetEntity="User", inversedBy="Card")
     * @JoinColumn(name="user_id", referencedColumnName="id")
     */
    protected $user;

    /**
     * @Column(name="post_title", type="string")
     */
    protected $cardType;
}

The difference here is I wrote @JoinColumn in both objects/entities. And in Doctrine example there is only one.
Now I would get what I think is Bidirectional relation. If i look at EER diagram, I can see one line pointing from user to card, and the other from card to user.

So basicly did I get this right?
Is the Doctrine documentation wrong? 😀
How would Bidirectional OneToOne relation look in EER diagram?

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-06-12T23:10:31+00:00Added an answer on June 12, 2026 at 11:10 pm

    The only difference is in the PHP class interface, i.e. in the presence or absence of the property that points back to the owner (e.g. the $customer property in the mentioned Doctrine example). In other words Doctrine just needs to know whether it should take care about a single property ($shipping) or two properties ($cart and $customer). There is no other difference. Therefore, the SQL code is the same (because one foreign key is sufficient for representing any 1:N relationship) and there would no difference in EER diagram neither (because in EER you typically do not solve such PHP-related implementation details).

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

Sidebar

Related Questions

I've just started playing around with Scala, and I just learned about how methods
I've recently started playing around with ASP.NET and I was just about to connect
I just started playing around with the WPF RibbonControl library from Microsoft (October 2010
I'm learning Java and just started playing around with mysql and am having a
I have no experience at all with OpenGL and just started playing around with
Just started playing around with ice_cube I've got a weekly schedule (with a granularity
I just started playing around with threading today and I ran into something that
I just started playing around with the 960 CSS framework and found that it
I'm just started on playing around with the canvas HTML5-object. For the sake of
I'm just getting started with ASP.NET MVC 2, and playing around with Validation. Let's

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.