One of the ManyToOne must not be null #6891

Closed
opened 2026-01-22 15:40:47 +01:00 by admin · 1 comment
Owner

Originally created by @helyakin on GitHub (Dec 17, 2021).

Feature Request

Q A
New Feature yes
RFC yes
BC Break no

Summary

Hello guy's here is my exemple :

Given the following object

#[ORM\Entity(repositoryClass: BoatRepository::class)]
#[ORM\Table(name: 'boat')]
class Boat
{
    #[ORM\Id]
    #[ORM\Column(type: 'ulid', unique: true)]
    private Ulid $id;

    #[ORM\Column(type: 'string', length: 100)]
    private string $property;

    #[ORM\Column(type: 'string', length: 255)]
    private string $value;

    #[ORM\Column(type: 'string', length: 255, nullable: true)]
    private ?string $type;

    #[ORM\ManyToOne(targetEntity: Company::class, inversedBy: 'boats')]
    private ?Company $company;

    #[ORM\ManyToOne(targetEntity: Owner::class, inversedBy: 'boats')]
    private ?Owner $owner;
}

It would be amazing to have and easy constraint attribute that would execute an SQL request stating that the boat CANNOT be without a company and without a user at the same time, and must at list have one of those.

Something who would look like this:

#[ORM\Entity(repositoryClass: BoatRepository::class)]
#[ORM\Table(name: 'signature_style', hasAtList: [Owner::class, Company::class])]
class Boat
{
 //...
}
Originally created by @helyakin on GitHub (Dec 17, 2021). ### Feature Request <!-- Fill in the relevant information below to help triage your issue. --> | Q | A |------------ | ------ | New Feature | yes | RFC | yes | BC Break | no #### Summary Hello guy's here is my exemple : Given the following object ``` #[ORM\Entity(repositoryClass: BoatRepository::class)] #[ORM\Table(name: 'boat')] class Boat { #[ORM\Id] #[ORM\Column(type: 'ulid', unique: true)] private Ulid $id; #[ORM\Column(type: 'string', length: 100)] private string $property; #[ORM\Column(type: 'string', length: 255)] private string $value; #[ORM\Column(type: 'string', length: 255, nullable: true)] private ?string $type; #[ORM\ManyToOne(targetEntity: Company::class, inversedBy: 'boats')] private ?Company $company; #[ORM\ManyToOne(targetEntity: Owner::class, inversedBy: 'boats')] private ?Owner $owner; } ``` It would be amazing to have and easy constraint attribute that would execute an SQL request stating that the boat CANNOT be without a company and without a user at the same time, and must at list have one of those. Something who would look like this: ``` #[ORM\Entity(repositoryClass: BoatRepository::class)] #[ORM\Table(name: 'signature_style', hasAtList: [Owner::class, Company::class])] class Boat { //... } ```
admin closed this issue 2026-01-22 15:40:47 +01:00
Author
Owner

@beberlei commented on GitHub (Dec 18, 2021):

This is something you can enforce in your own logic, for example with Symfony Validator or Doctrine entity event.

@beberlei commented on GitHub (Dec 18, 2021): This is something you can enforce in your own logic, for example with Symfony Validator or Doctrine entity event.
Sign in to join this conversation.
1 Participants
Notifications
Due Date
No due date set.
Dependencies

No dependencies set.

Reference: doctrine/archived-orm#6891