I'd welcome a simple way to add index to a single column, some shorthand for this:
/**
* @ORM\Entity
* @ORM\Table(indexes={@Index(name="foo_idx", columns={"foo"})})
*/
class Foo
{
/** @ORM\Column(type="string") */
private $foo;
}
to be annotated directly with the column:
/** @ORM\Entity */
class Foo {
/** @ORM\Column(type="string", index=true) */
private $foo;
}
or in a similar way (like @ORM\Index for column). This is possible for unique indexes as Column(unique=true), so I think there should be similar annotation for non-unique indexes.
Any comments welcomed, I can eventually pull-request it if it makes sense for others too.
Seems like an unnecessary shortcut to me, much like unique (which can also be defined via @UniqueConstraint.
Possibly simplifying things on one side, but adding more paths where to look for index definitions.
Actually, this calls for dropping unique from the @Column annotation. Thoughts, @guilhermeblanco?
Well that's not exactly what I wanted but still better than current inconsistency in key definition. So, thumbs up for removing.
Just note that dropping unique from @Column will require all unique constraints to be declared in parent entity, no matter where the field is declared, as per #6248.
@Ocramius any idea on how this relates with the JPA 2.2 stuff?
@lcobucci no, sorry.
From JPA 2.2 spec:

There is no indexed or similar attribute.
So I wouldn't remove the unique property...
With that simple annotation, we could put indexes on single-columns added from Traits.
Now, i have no idea on how i can manage index from a trait.
Most helpful comment
With that simple annotation, we could put indexes on single-columns added from Traits.
Now, i have no idea on how i can manage index from a trait.