Skip to content

Instantly share code, notes, and snippets.

Created September 4, 2013 09:57
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save anonymous/6435032 to your computer and use it in GitHub Desktop.
Save anonymous/6435032 to your computer and use it in GitHub Desktop.
Example of a OneToOne, bidirectional, PK as FK association.
<?php
class Book
{
/**
* @ORM\Id
* @ORM\Column()
* @ORM\GeneratedValue(strategy="IDENTITY")
*/
protected $id;
/**
* @ORM\OneToOne(targetEntity="HardCover", mappedBy="book", cascade={"persist"})
*/
protected $hardCover;
public function getHardCover()
{
return $this->hardCover;
}
}
class HardCover
{
/**
* @ORM\Id
* @ORM\OneToOne(targetEntity="Book", inversedBy="hardCover")
* @ORM\JoinColumns({
* @ORM\JoinColumn(name="id_book", referencedColumnName="id")
* })
*/
protected $book;
public function getBook()
{
return $this->book;
}
public function setBook(Book $book)
{
$this->book = $book;
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment