Created
May 28, 2012 07:43
-
-
Save IamSmith/2817892 to your computer and use it in GitHub Desktop.
Student Doctrine ORM Example
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?php | |
/** | |
* @ORM\Entity | |
* @ORM\Table(name="student") | |
* | |
*/ | |
class Student { | |
/** | |
* @ORM\Id | |
* @ORM\Column(name="id", type="integer") | |
* @ORM\GeneratedValue | |
*/ | |
protected $id; | |
/** | |
* @ORM\Column(name="name", type="string") | |
*/ | |
protected $name; | |
/** | |
* @OneToOne(targetEntity="Address") | |
*/ | |
protected $address; | |
/** | |
* @OneToMany(targetEntity="Year", mappedBy="students", cascade={"all"}) | |
*/ | |
protected $year; | |
/** | |
* @ManyToMany(targetEntity="Class", inversedBy="students") | |
* @JoinTable(name="student_to_class", | |
* joinColumns={@JoinColumn(name="student_id", referencedColumnName="id")}, | |
* inverseJoinColumns={@JoinColumn(name="class_id", referencedColumnName="id")} | |
* ) | |
*/ | |
protected $classes; | |
} | |
/** | |
* @ORM\Entity | |
* @ORM\Table(name="address") | |
* | |
*/ | |
class Address { | |
/** | |
* @ORM\Id | |
* @ORM\Column(name="id", type="integer") | |
* @ORM\GeneratedValue | |
*/ | |
protected $id; | |
/** | |
* @ORM\Column(name="address_line_1", type="string") | |
*/ | |
protected $addressLine1; | |
/** | |
* @ORM\Column(name="postcode", type="string", length=8) | |
*/ | |
protected $postcode; | |
} | |
/** | |
* @ORM\Entity | |
* @ORM\Table(name="class") | |
* | |
*/ | |
class Class { | |
/** | |
* @ORM\Id | |
* @ORM\Column(name="id", type="integer") | |
* @ORM\GeneratedValue | |
*/ | |
protected $id; | |
/** | |
* @ORM\Column(name="subject", type="string") | |
*/ | |
protected $subject; | |
/** | |
* @ManyToMany(targetEntity="Student", mappedBy="classes") | |
*/ | |
protected $students; | |
} | |
/** | |
* @ORM\Entity | |
* @ORM\Table(name="year") | |
* | |
*/ | |
class Year { | |
/** | |
* @ORM\Id | |
* @ORM\Column(name="id", type="integer") | |
* @ORM\GeneratedValue | |
*/ | |
protected $id; | |
/** | |
* @ORM\Column(name="year", type="integer") | |
*/ | |
protected $year; | |
/** | |
* @ManyToOne(targetEntity="Student", cascade={"all"}) | |
*/ | |
protected $students; | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment