I am developing using zend framework and doctrine2.1.
I have generated entities from database.
But the problem is: Doctrine doesn't recognize my indexes. They are not marked in entity annotations at all.
And when I go to validate-schema and dump sql from orm:schema-tool:update --dump-sql
it generates sql to drop all my indexes across whole database.
I found that Doctrine has following annotation used for defining indexes:
indexes={@index(name="index_name",
columns={"database_column1","database_column2"}
)}
But this allows me to define one index for multiple columns and I don't really need that.
What I want is the ability to define multiple indexes on multiple columns, one index per column.
Is there a way I can achieve this? Is there a way that I can have annotation that defines multiple indexes.
I would say you can insert multiple indexes in the indexes property (but I haven't had the time to test it):
indexes={
@ORM\Index(name="index_name", columns={"database_column1","database_column2"}),
@ORM\Index(name="index_name2", columns={"database_column1"}),
@ORM\Index(name="index_name3", columns={"database_column2"})
}
Hope this helps you
Here is an example:
/**
* @Entity
* @Table(name="serial_number",indexes={
* @index(name="product_idx", columns={"product_id"}),
* })
*/
class SerialNumber { // Entity Class
/**
* @var int
*
* @Id
* @GeneratedValue
* @Column(type="integer")
*/
protected $id;
/**
* @Column(name="created_at", type="datetime")
* @var \DateTime
* */
protected $created;
/**
* @Column(name="updated_at", type="datetime")
* @var \DateTime
* */
protected $updated;
/**
* @Column(name="product_id", type="integer")
*/
protected $productID;
}
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With