8000 Allow #[Index] on properties instead of only the entire class. · Issue #11982 · doctrine/orm · GitHub
[go: up one dir, main page]
More Web Proxy on the site http://driver.im/
Skip to content
Allow #[Index] on properties instead of only the entire class. #11982
Open
@jannes-io

Description

@jannes-io

Feature Request

What

Going to keep this RFC short and to the point. The example speaks for itself.

Add TARGET_PROPERTY to #[Index] attribute.

Why

Making re-usable traits.

Now:

trait SomeCommonFields
{
    #[ORM\Column(type: 'integer')]
    public int $shared;
}

#[ORM\Entity]
#[ORM\Index('shared_field_idx', fields: ['shared'])] // we don't even know the fields, we have to look into the trait to find the names of the fields..
class A
{
    use SomeCommonFields;
}

#[ORM\Entity]
#[ORM\Index('shared_field_idx', fields: ['shared'])]
class B
{
    use SomeCommonFields;
}

Better:

trait SomeCommonFields
{
    #[ORM\Index]
    #[ORM\Column(type: 'integer')]
    public int $shared;
}

#[ORM\Entity]
class A
{
    use SomeCommonFields;
}

#[ORM\Entity]
class B
{
    use SomeCommonFields;
}

How

Same way unique already works on Column today, it could just be included in Column, or like the example, make the Index attribute work on properties too. Auto generate some index name and grab the property it's attached to as the "fields".

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions

      0