Typed Properties and default column/association types #6358

Closed
opened 2026-01-22 15:31:41 +01:00 by admin · 3 comments
Owner

Originally created by @beberlei on GitHub (Dec 1, 2019).

Feature Request

Q A
New Feature yes
RFC no
BC Break no

Summary

When declaring a type on a property, this should act as a default for field type or ManyToOne/OneToOne targetEntity.

class User
{
    /** @ORM\Column */
    public int $id; // defaults to type="integer"

   /** @ORM\ManyToOne */
   public Email $email; // defaults to targetEntity=Email::class
}

The relevant code would be in ClassMetadataInfo::mapField, mapManyToOne and mapOneToOne. Whenever type or targetEntity is missing, it could look this up in reflection property instead if it has a type.

Originally created by @beberlei on GitHub (Dec 1, 2019). ### Feature Request | Q | A |------------ | ------ | New Feature | yes | RFC | no | BC Break | no #### Summary When declaring a type on a property, this should act as a default for field type or ManyToOne/OneToOne targetEntity. ```php class User { /** @ORM\Column */ public int $id; // defaults to type="integer" /** @ORM\ManyToOne */ public Email $email; // defaults to targetEntity=Email::class } ``` The relevant code would be in `ClassMetadataInfo::mapField`, `mapManyToOne` and `mapOneToOne`. Whenever `type` or `targetEntity` is missing, it could look this up in reflection property instead if it has a type.
admin closed this issue 2026-01-22 15:31:42 +01:00
Author
Owner

@renanbr commented on GitHub (Dec 2, 2019):

Could we expect it'll also detect nullable properties?

/** @ORM\Column */
public ?string $name;
@renanbr commented on GitHub (Dec 2, 2019): Could we expect it'll also detect `nullable` properties? ```php /** @ORM\Column */ public ?string $name; ```
Author
Owner

@Lustmored commented on GitHub (Jan 26, 2021):

I have submitted #8439 as an attempt to implement features discussed in this issue. It probably still needs work, but it would be great to get some feedback :)

@Lustmored commented on GitHub (Jan 26, 2021): I have submitted #8439 as an attempt to implement features discussed in this issue. It probably still needs work, but it would be great to get some feedback :)
Author
Owner

@beberlei commented on GitHub (Mar 21, 2021):

Fixed in #8439

@beberlei commented on GitHub (Mar 21, 2021): Fixed in #8439
Sign in to join this conversation.
1 Participants
Notifications
Due Date
No due date set.
Dependencies

No dependencies set.

Reference: doctrine/archived-orm#6358