Do the doctrine definitions of the master preview attachment in the sub classes

This makes lazy fetching works and saves some db queries.
This commit is contained in:
Jan Böhmer 2023-07-19 22:49:40 +02:00
parent 2c6de84c9a
commit 2ddfe48aba
14 changed files with 73 additions and 6 deletions

View file

@ -22,6 +22,8 @@ declare(strict_types=1);
namespace App\Entity\Parts;
use App\Entity\Attachments\Attachment;
use App\Entity\Attachments\AttachmentTypeAttachment;
use App\Repository\Parts\CategoryRepository;
use Doctrine\DBAL\Types\Types;
use Doctrine\Common\Collections\ArrayCollection;
@ -118,6 +120,10 @@ class Category extends AbstractPartsContainingDBElement
#[ORM\OrderBy(['name' => 'ASC'])]
protected Collection $attachments;
#[ORM\OneToOne(targetEntity: CategoryAttachment::class)]
#[ORM\JoinColumn(name: 'id_preview_attachment', onDelete: 'SET NULL')]
protected ?Attachment $master_picture_attachment = null;
/** @var Collection<int, CategoryParameter>
*/
#[Assert\Valid]

View file

@ -22,6 +22,8 @@ declare(strict_types=1);
namespace App\Entity\Parts;
use App\Entity\Attachments\Attachment;
use App\Entity\Attachments\AttachmentTypeAttachment;
use App\Repository\Parts\FootprintRepository;
use App\Entity\Base\AbstractStructuralDBElement;
use Doctrine\Common\Collections\ArrayCollection;
@ -59,6 +61,10 @@ class Footprint extends AbstractPartsContainingDBElement
#[ORM\OrderBy(['name' => 'ASC'])]
protected Collection $attachments;
#[ORM\OneToOne(targetEntity: FootprintAttachment::class)]
#[ORM\JoinColumn(name: 'id_preview_attachment', onDelete: 'SET NULL')]
protected ?Attachment $master_picture_attachment = null;
/**
* @var FootprintAttachment|null
*/

View file

@ -22,6 +22,8 @@ declare(strict_types=1);
namespace App\Entity\Parts;
use App\Entity\Attachments\Attachment;
use App\Entity\Attachments\AttachmentTypeAttachment;
use App\Repository\Parts\ManufacturerRepository;
use App\Entity\Base\AbstractStructuralDBElement;
use Doctrine\Common\Collections\ArrayCollection;
@ -59,6 +61,10 @@ class Manufacturer extends AbstractCompany
#[ORM\OrderBy(['name' => 'ASC'])]
protected Collection $attachments;
#[ORM\OneToOne(targetEntity: ManufacturerAttachment::class)]
#[ORM\JoinColumn(name: 'id_preview_attachment', onDelete: 'SET NULL')]
protected ?Attachment $master_picture_attachment = null;
/** @var Collection<int, ManufacturerParameter>
*/
#[Assert\Valid]

View file

@ -22,6 +22,8 @@ declare(strict_types=1);
namespace App\Entity\Parts;
use App\Entity\Attachments\Attachment;
use App\Entity\Attachments\AttachmentTypeAttachment;
use App\Repository\Parts\MeasurementUnitRepository;
use Doctrine\DBAL\Types\Types;
use App\Entity\Base\AbstractStructuralDBElement;
@ -90,6 +92,10 @@ class MeasurementUnit extends AbstractPartsContainingDBElement
#[ORM\OrderBy(['name' => 'ASC'])]
protected Collection $attachments;
#[ORM\OneToOne(targetEntity: MeasurementUnitAttachment::class)]
#[ORM\JoinColumn(name: 'id_preview_attachment', onDelete: 'SET NULL')]
protected ?Attachment $master_picture_attachment = null;
/** @var Collection<int, MeasurementUnitParameter>
*/
#[Assert\Valid]

View file

@ -22,6 +22,7 @@ declare(strict_types=1);
namespace App\Entity\Parts;
use App\Entity\Attachments\AttachmentTypeAttachment;
use App\Repository\PartRepository;
use Doctrine\DBAL\Types\Types;
use App\Entity\Attachments\Attachment;
@ -102,7 +103,7 @@ class Part extends AttachmentContainingDBElement
* @var Attachment|null
*/
#[Assert\Expression('value == null or value.isPicture()', message: 'part.master_attachment.must_be_picture')]
#[ORM\ManyToOne(targetEntity: Attachment::class)]
#[ORM\ManyToOne(targetEntity: PartAttachment::class)]
#[ORM\JoinColumn(name: 'id_preview_attachment', onDelete: 'SET NULL')]
protected ?Attachment $master_picture_attachment = null;

View file

@ -22,6 +22,7 @@ declare(strict_types=1);
namespace App\Entity\Parts;
use App\Entity\Attachments\Attachment;
use App\Repository\Parts\StorelocationRepository;
use Doctrine\DBAL\Types\Types;
use Doctrine\Common\Collections\ArrayCollection;
@ -109,6 +110,10 @@ class Storelocation extends AbstractPartsContainingDBElement
#[ORM\OneToMany(targetEntity: StorelocationAttachment::class, mappedBy: 'element', cascade: ['persist', 'remove'], orphanRemoval: true)]
protected Collection $attachments;
#[ORM\OneToOne(targetEntity: StorelocationAttachment::class)]
#[ORM\JoinColumn(name: 'id_preview_attachment', onDelete: 'SET NULL')]
protected ?Attachment $master_picture_attachment = null;
/********************************************************************************
*
* Getters

View file

@ -22,6 +22,8 @@ declare(strict_types=1);
namespace App\Entity\Parts;
use App\Entity\Attachments\Attachment;
use App\Entity\Attachments\AttachmentTypeAttachment;
use App\Repository\Parts\SupplierRepository;
use App\Entity\PriceInformations\Orderdetail;
use Doctrine\Common\Collections\ArrayCollection;
@ -91,6 +93,10 @@ class Supplier extends AbstractCompany
#[ORM\OrderBy(['name' => 'ASC'])]
protected Collection $attachments;
#[ORM\OneToOne(targetEntity: SupplierAttachment::class)]
#[ORM\JoinColumn(name: 'id_preview_attachment', onDelete: 'SET NULL')]
protected ?Attachment $master_picture_attachment = null;
/** @var Collection<int, SupplierParameter>
*/
#[Assert\Valid]