I have a scenario where employees and organizations tables are mapped in the separate table called org_employees
.
I have no issue in adding the rows for the employees table and organization tables individually, but my question is how can i add the records for the org_employees
table. Do i need to create a separate entity for org_employees
table mean, if yes how the ORM relation happen. can you anyone guide me on this.
Employee
Entity:
<?php
namespace Employee\Entity;
use Doctrine\Common\Collections\ArrayCollection;
use Doctrine\ORM\Mapping as ORM;
use Library\Entity\BaseEntity;
/**
* @ORM\Entity
* @ORM\Table(name="employees")
*/
class Employee extends BaseEntity{
/**
* @ORM\Column(name="employee_code", type="string")
* @var string
*/
protected $empCode;
public function getEmpCode() {
return $this->empCode;
}
public function setEmpCode($empCode) {
$this->empCode = $empCode;
return $this;
}
public function __toString() {
return __CLASS__ . ": [id: {$this->id}, name: {$this->name}]";
}
}
Organization
Entity:
<?php
namespace Organization\Entity;
use Doctrine\Common\Collections\ArrayCollection;
use Doctrine\ORM\Mapping as ORM;
use Library\Entity\BaseEntity;
/**
* @ORM\Entity
* @ORM\Table(name="organizations")
*/
class Organization extends BaseEntity{
/**
* @ORM\Column(name="name", type="string")
* @var string
*/
protected $name;
public function getName() {
return $this->name;
}
public function setName($name) {
$this->name = $name;
}
public function __toString() {
return __CLASS__ . ": [id: {$this->id}, name: {$this->name}]";
}
}