Quantcast
Channel: Active questions tagged symfony4 - Stack Overflow
Viewing all articles
Browse latest Browse all 3925

Mapping multiple entities under a single field

$
0
0

Is there a way to have a single field in an entity tied to multiple different entities?

I have a "Task" entity which can be associated with either the Customer entity or Supplier entity (never both). Right now both fields are separate.

I need to use this in my TaskType form so that users can select which Customer/Supplier to associate the Task with, ideally under a single field as I plan on adding more entities that it can associate with.

/**
 * @ORM\ManyToOne(targetEntity="App\Entity\Customer", inversedBy="tasks")
 */
private $customer;
/**
 * @ORM\ManyToOne(targetEntity="App\Entity\Supplier", inversedBy="tasks")
 */
private $supplier;

public function getCustomer(): ?Customer
{
    return $this->customer;
}
public function setCustomer(?Customer $customer): self
{
    $this->customer = $customer;
    return $this;
}
public function getSupplier(): ?Supplier
...etc

Viewing all articles
Browse latest Browse all 3925

Trending Articles