The following relationship exists between two entities:
class Clients
{
//...
/**
* Dealership id
*
* @ManyToOne(targetEntity="Dealerships", inversedBy="clients", fetch="EXTRA_LAZY")
* @JoinColumn(name="dealership_id", referencedColumnName="id")
*/
private $dealershipId;
//...
}
Notice that there is a relationship with the Dealerships
entity through the dealership_id
field.
In the Dealerships
ed entity I have the following structure:
class Dealerships
{
/**
* @var int
*
* @ORM\Column(name="id", type="integer")
* @ORM\Id
* @ORM\GeneratedValue(strategy="AUTO")
*/
private $id;
/**
* @var int
*
* @ORM\Column(name="active", type="integer")
*/
private $active;
//...
}
Notice that the active
property exists.
If there is a record with ID 1 in the Dealerships
table, in the clients
object simply do the following:
$client = new Clients();
$client->setDealershipId(1);
The code above works because there is ID 1, but in the relation I want to consider 1 more field, the active
, that is, only accept the relation if the field active
is equal to 1.
Is it possible to do this using Doctrine?