Я работаю в Symfony 4 и блокирую отношения ManyToMany, я хотел бы иметь ссылку на каждую статью, зная, что у всех поставщиков может быть одна и та же общая статья, но с другой ссылкой. Вот мои 2 сущности:
Артикул:
<?php
namespace App\Entity;
use Doctrine\Common\Collections\ArrayCollection;
use Doctrine\ORM\Mapping as ORM;
/**
* @ORM\Entity(repositoryClass="App\Repository\ArticlesRepository")
*/
class Article
{
/**
* @ORM\Id()
* @ORM\GeneratedValue()
* @ORM\Column(type="integer")
*/
private $id;
/**
* @ORM\Column(type="string", length=255)
*/
private $id_tactill;
/**
* @ORM\Column(type="string", length=255)
*/
private $name;
/**
* @ORM\Column(type="float", nullable=true)
*/
private $price;
/**
* @ORM\Column(type="string", length=255, nullable=true)
*/
private $reference;
/**
* @ORM\Column(type="boolean")
*/
private $in_stock;
/**
* @ORM\Column(type="string", length=255, nullable=true)
*/
private $image;
/**
* @ORM\Column(type="string", length=255, nullable=true)
*/
private $reference_supplier;
/**
* @ORM\Column(type="string", length=255, nullable=true)
*/
private $taxes;
/**
* @ORM\ManyToMany(targetEntity="Fournisseur", inversedBy="Articles")
* @ORM\JoinTable(name="articles_fournisseurs")
*/
private $fournisseurs;
public function __construct() {
$this->fournisseurs = new ArrayCollection();
}
public function getId(): ?int
{
return $this->id;
}
/**
* @return mixed
*/
public function getIdTactill()
{
return $this->id_tactill;
}
/**
* @param mixed $id_tactill
*/
public function setIdTactill($id_tactill): void
{
$this->id_tactill = $id_tactill;
}
public function getName(): ?string
{
return $this->name;
}
public function setName(string $name): self
{
$this->name = $name;
return $this;
}
public function getPrice(): ?float
{
return $this->price;
}
public function setPrice(float $price): self
{
$this->price = $price;
return $this;
}
public function getReference(): ?string
{
return $this->reference;
}
public function setReference(string $reference): self
{
$this->reference = $reference;
return $this;
}
public function getInStock(): ?bool
{
return $this->in_stock;
}
public function setInStock(bool $in_stock): self
{
$this->in_stock = $in_stock;
return $this;
}
public function getImage(): ?string
{
return $this->image;
}
public function setImage(string $image): self
{
$this->image = $image;
return $this;
}
public function getReferenceSupplier(): ?string
{
return $this->reference_supplier;
}
public function setReferenceSupplier(string $reference_supplier): self
{
$this->reference_supplier = $reference_supplier;
return $this;
}
public function getTaxes()
{
return $this->taxes;
}
public function setTaxes($taxes): void
{
$this->taxes = $taxes;
}
}
Поставщик:
<?php
namespace App\Entity;
use Doctrine\Common\Collections\ArrayCollection;
use Symfony\Component\HttpFoundation\File\File;
use Vich\UploaderBundle\Mapping\Annotation as Vich;
use Doctrine\ORM\Mapping as ORM;
/**
* @ORM\Entity(repositoryClass="App\Repository\FournisseursRepository")
* @Vich\Uploadable
*/
class Fournisseur
{
/**
* @ORM\Id()
* @ORM\GeneratedValue()
* @ORM\Column(type="integer")
*/
private $id;
/**
* @ORM\Column(type="string", length=255)
*
* @var string
*/
private $category;
/**
* @ORM\Column(type="string", length=255)
*
* @var string
*/
private $civility;
/**
* @ORM\Column(type="text")
*
*/
private $name;
/**
* @ORM\Column(type="string", length=255)
*
* @var string
*/
private $company;
/**
* @ORM\Column(type="string", length=255, nullable=true)
*
* @var string
*/
private $named;
/**
* @ORM\Column(type="string", length=255)
*
* @var string
*/
private $surname;
/**
* @ORM\Column(type="string", length=255)
*
* @var string
*/
private $building;
/**
* @ORM\Column(type="string", length=255)
*
* @var string
*/
private $street;
/**
* @ORM\Column(type="string", length=255)
*
* @var string
*/
private $other;
/**
* @ORM\Column(type="integer", length=5)
*
* @var integer
*/
private $zipcode;
/**
* @ORM\Column(type="string", length=255)
*
* @var string
*/
private $city;
/**
* @ORM\Column(type="string", length=255)
*
* @var string
*/
private $country;
/**
* @ORM\Column(type="string", length=255)
*
* @var string
*/
private $url;
/**
* @ORM\Column(type="string", length=255)
*
* @var string
*/
private $login;
/**
* @ORM\Column(type="string", length=255)
*
* @var string
*/
private $passwordSite;
/**
* NOTE: This is not a mapped field of entity metadata, just a simple property.
*
* @Vich\UploadableField(mapping="fournisseur_image", fileNameProperty="imageName", size="imageSize")
*
* @var File
*/
private $imageFile;
/**
* @ORM\Column(type="string", length=255)
*
* @var string
*/
private $imageName;
/**
* @ORM\Column(type="integer")
*
* @var integer
*/
private $imageSize;
/**
* @ORM\Column(type="string", length=255)
*/
private $title;
/**
* @ORM\Column(type="string", length=255)
*/
private $type;
/**
* @ORM\Column(type="string", length=255)
*/
private $phone1;
/**
* @ORM\Column(type="string", length=255)
*/
private $phone2;
/**
* @ORM\Column(type="string", length=255)
*/
private $fax;
/**
* @ORM\Column(type="string", length=255)
*/
private $email;
/**
* @ORM\Column(type="text")
*/
private $note;
/**
* @ORM\ManyToMany(targetEntity="Article", mappedBy="fournisseurs")
*/
private $articles;
public function __construct() {
$this->articles = new ArrayCollection();
}
public function getId(): ?int
{
return $this->id;
}
/**
* @return string
*/
public function getCategory(): ?string
{
return $this->category;
}
/**
* @param string $category
*/
public function setCategory(string $category): void
{
$this->category = $category;
}
/**
* @return string
*/
public function getCivility(): ?string
{
return $this->civility;
}
/**
* @param string $civility
*/
public function setCivility(string $civility): void
{
$this->civility = $civility;
}
/**
* @return mixed
*/
public function getName()
{
return $this->name;
}
/**
* @param mixed $name
*/
public function setName($name): void
{
$this->name = $name;
}
/**
* @return string
*/
public function getCompany(): ?string
{
return $this->company;
}
/**
* @param string $company
*/
public function setCompany(string $company): void
{
$this->company = $company;
}
/**
* @return string
*/
public function getNamed(): ?string
{
return $this->named;
}
/**
* @param string $named
*/
public function setNamed(string $named): void
{
$this->named = $named;
}
/**
* @return string
*/
public function getSurname(): ?string
{
return $this->surname;
}
/**
* @param string $surname
*/
public function setSurname(string $surname): void
{
$this->surname = $surname;
}
/**
* @return string
*/
public function getBuilding(): ?string
{
return $this->building;
}
/**
* @param string $building
*/
public function setBuilding(string $building): void
{
$this->building = $building;
}
/**
* @return string
*/
public function getStreet(): ?string
{
return $this->street;
}
/**
* @param string $street
*/
public function setStreet(string $street): void
{
$this->street = $street;
}
/**
* @return string
*/
public function getOther(): ?string
{
return $this->other;
}
/**
* @param string $other
*/
public function setOther(string $other): void
{
$this->other = $other;
}
/**
* @return int
*/
public function getZipcode(): ?int
{
return $this->zipcode;
}
/**
* @param int $zipcode
*/
public function setZipcode(int $zipcode): void
{
$this->zipcode = $zipcode;
}
/**
* @return string
*/
public function getCity(): ?string
{
return $this->city;
}
/**
* @param string $city
*/
public function setCity(string $city): void
{
$this->city = $city;
}
/**
* @return string
*/
public function getCountry(): ?string
{
return $this->country;
}
/**
* @param string $country
*/
public function setCountry(string $country): void
{
$this->country = $country;
}
/**
* @return string
*/
public function getUrl(): ?string
{
return $this->url;
}
/**
* @param string $url
*/
public function setUrl(string $url): void
{
$this->url = $url;
}
/**
* @return string
*/
public function getLogin(): ?string
{
return $this->login;
}
/**
* @param string $login
*/
public function setLogin(string $login): void
{
$this->login = $login;
}
/**
* @return string
*/
public function getPasswordSite(): ?string
{
return $this->passwordSite;
}
/**
* @param string $passwordSite
*/
public function setPasswordSite(string $passwordSite): void
{
$this->passwordSite = $passwordSite;
}
/**
* @param File|\Symfony\Component\HttpFoundation\File\UploadedFile $imageFile
*/
public function setImageFile(?File $imageFile = null): void
{
$this->imageFile = $imageFile;
}
public function getImageFile(): ?File
{
return $this->imageFile;
}
public function setImageName(?string $imageName): void
{
$this->imageName = $imageName;
}
public function getImageName(): ?string
{
return $this->imageName;
}
public function setImageSize(?int $imageSize): void
{
$this->imageSize = $imageSize;
}
public function getImageSize(): ?int
{
return $this->imageSize;
}
public function getTitle(): ?string
{
return $this->title;
}
public function setTitle(string $title): self
{
$this->title = $title;
return $this;
}
public function getType(): ?string
{
return $this->type;
}
public function setType(string $type): self
{
$this->type = $type;
return $this;
}
public function getPhone1(): ?string
{
return $this->phone1;
}
public function setPhone1(string $phone1): self
{
$this->phone1 = $phone1;
return $this;
}
public function getPhone2(): ?string
{
return $this->phone2;
}
public function setPhone2(string $phone2): self
{
$this->phone2 = $phone2;
return $this;
}
public function getFax(): ?string
{
return $this->fax;
}
public function setFax(string $fax): self
{
$this->fax = $fax;
return $this;
}
public function getEmail(): ?string
{
return $this->email;
}
public function setEmail(string $email): self
{
$this->email = $email;
return $this;
}
public function getNote(): ?string
{
return $this->note;
}
public function setNote(string $note): self
{
$this->note = $note;
return $this;
}
}
Мне нужно связать другую ссылку на продукт в зависимости от поставщика.
Спасибо за помощь.