Symfony学说映射

时间:2018-11-25 21:27:11

标签: doctrine symfony4

我有2个实体:

费用和供应商。

一个供应商有很多费用点。

我遇到了错误:

  

1062-键“ UNIQ_2D3A8DA62ADD6D8C”的条目“ 4”重复

因为我正尝试向供应商添加新费用。

但是我的实体上有ManyToOne。

费用实体文件:

<?php

namespace App\Entity;

use Doctrine\ORM\Mapping as ORM;

/**
 * @ORM\Entity
 */
class Expense
{
/**
 * @ORM\Id()
 * @ORM\GeneratedValue()
 * @ORM\Column(type="integer")
 */
private $id;
/**
 * @ORM\ManyToOne(targetEntity="App\Entity\Supplier")
 * @ORM\JoinColumn(nullable=false)
 */
private $supplier;
/**
 * @ORM\Column(type="string", length=50)
 */
private $amount;
/**
 * @ORM\Column(type="string", length=50)
 */
private $invoice_id;
/**
 * @ORM\Column(type="date")
 */
private $date;

public function getId(): ?int
{
    return $this->id;
}

public function getAmount(): ?string
{
    return $this->amount;
}

public function setAmount(string $amount): self
{
    $this->amount = $amount;

    return $this;
}

public function getInvoiceId(): ?string
{
    return $this->invoice_id;
}

public function setInvoiceId(string $invoice_id): self
{
    $this->invoice_id = $invoice_id;

    return $this;
}

public function getDate(): ?\DateTimeInterface
{
    return $this->date;
}

public function setDate(\DateTimeInterface $date): self
{
    $this->date = $date;

    return $this;
}

public function getSupplier(): ?Supplier
{
    return $this->supplier;
}

public function setSupplier(?Supplier $supplier): self
{
    $this->supplier = $supplier;
    return $this;
}}

供应商实体文件:

<?php

namespace App\Entity;

use Doctrine\ORM\Mapping as ORM;

/**
 * @ORM\Entity
 */
class Supplier
{
    /**
     * @ORM\Id()
     * @ORM\GeneratedValue()
     * @ORM\Column(type="integer")
     */
    private $id;
    /**
     * @ORM\Column(type="string", length=50)
     */
    private $name;
    /**
     * @ORM\Column(type="string", length=50)
     */
    private $tax_id;
    /**
     * @ORM\Column(type="integer", length=50)
     */
    private $category;

    public function __toString()
    {
        return (string)$this->name;
    }

    public function getId(): ?int
    {
        return $this->id;
    }

    public function getName(): ?string
    {
        return $this->name;
    }

    public function setName(string $name): self
    {
        $this->name = $name;

        return $this;
    }

    public function getTaxId(): ?string
    {
        return $this->tax_id;
    }

    public function setTaxId(string $tax_id): self
    {
        $this->tax_id = $tax_id;

        return $this;
    }

    public function getCategory(): ?int
    {
        return $this->category;
    }

    public function setCategory(int $category): self
    {
        $this->category = $category;

        return $this;
    }
}

我在Google上尝试了很多。

但没有解决办法

0 个答案:

没有答案