title: Doctrine - OneToOne Unidirectional vs OneToOne Bidirectional
body: <p>I joust started playing around with Doctrine ORM library, and Im learning about all associations between tables.</p>
  
  <p>So Im stuck with differences in Unidirectional and Bidirectional relation.</p>
  
  <p>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.</p>
  
  <p>Now, Im reading through Doctrine documentation about relations and there you have:
  <a href="http://docs.doctrine-project.org/projects/doctrine-orm/en/latest/reference/association-mapping.html#one-to-one-unidirectional">Unidirectional</a> and <a href="http://docs.doctrine-project.org/projects/doctrine-orm/en/latest/reference/association-mapping.html#one-to-one-bidirectional">Bidirectional</a> associations.</p>
  
  <p>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.</p>
  
  <p>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.</p>
  
  <p>So what I did, is this, lets say I have User and Card Entity, and want relation to be OneToOne Bidirectional.</p>
  
  <pre><code>    /**
   * @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;
  }
  </code></pre>
  
  <p>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.</p>
  
  <p>So basicly did I get this right?
  Is the Doctrine documentation wrong? :D
  How would Bidirectional OneToOne relation look in EER diagram?</p>
  
  <p>Thanks!</p>