I want to check whether my syntax is correct for cascading removal of the following entities, I want when I delete a Subject or a User it cascades and deletes the Teacher entity related to them.
Teachers Entity
class Teacher{
/**
* @ORM\Id
* @ORM\GeneratedValue(strategy="AUTO")
* @ORM\Column(type="integer")
**/
protected $id;
/** @ORM\Column(type="integer")
* @ORM\ManyToOne(targetEntity="Subject")
* @ORM\JoinColumn(name="subjectId", referencedColumnName="id", onDelete="CASCADE")
* */
protected $subjectId;
/** @ORM\Column(type="integer")
* @ORM\ManyToOne(targetEntity="User")
* @ORM\JoinColumn(name="userId", referencedColumnName="id", onDelete="CASCADE")
* */
protected $userId;
}
Subject Entity
/** @ORM\Entity */
class Subject{
/**
* @ORM\Id
* @ORM\GeneratedValue(strategy="AUTO")
* @ORM\Column(type="integer")
*/
protected $id;
/** @ORM\Column(type="integer") */
protected $sectionId;
/** @ORM\Column(type="string") */
protected $subjectName;
Users Entity
/** @ORM\Entity */
class User {
/**
* @ORM\Id
* @ORM\GeneratedValue(strategy="AUTO")
* @ORM\Column(type="integer")
*/
protected $id;
/** @ORM\Column(type="string") */
protected $username;
/** @ORM\Column(type="string") */
protected $password;
/** @ORM\Column(type="string") */
protected $first_name;
/** @ORM\Column(type="string") */
protected $middle_name;
/** @ORM\Column(type="string") */
protected $last_name;
/** @ORM\Column(type="string") */
protected $sex;
/** @ORM\Column(type="date") */
protected $dob;
/** @ORM\Column(type="boolean") */
protected $is_active;
/** @ORM\Column(type="boolean") */
protected $is_admin;
/** @ORM\Column(type="string") */
protected $email;
/** @ORM\Column(type="string") */
protected $address;
/** @ORM\Column(type="string") */
protected $bloodTypeId;
/** @ORM\Column(type="string") */
protected $photo;
/** @ORM\Column(type="integer") */
protected $userTypeId;
Because it doesn't seem to work when I delete a User or a Subject, I am expecting the teacher related to their fields be deleted as Well.