Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How do I set more than one index for a table in a doctrine 2 entity file (using annotations)?

I have two columns representing a start date and an end date. If I wanted to create a joint index for them, I would do:

* @Table(name="concerts", indexes={@Index(name="concert_dates", columns={"date_start","date_end"})})

But how would I do an index for each of them ? Is the following way correct?

* @Table(name="concerts", indexes={@Index(name="concert_date_start", columns={"date_start"}), @Index(name="concert_date_end", columns={"date_end"})})
like image 530
Doron Avatar asked Mar 18 '11 08:03

Doron


2 Answers

Documentation says that indexes is an array of @Index annotations. So I'd say yes, it is correct.

like image 183
Jakub Lédl Avatar answered Oct 22 '22 16:10

Jakub Lédl


Yes it works fine for me. I have done this:

/**
 * Class ProductDisplayArea
 * @ORM\Entity
 * @ORM\Table(name="product_display_area", indexes={
 *      @Index(name="product_display_area_product_id", columns={"product_id"}),
 *      @Index(name="product_display_area_productCat_id", columns={"productCat_id"}),
 *      @Index(name="product_display_area_productSCat_id", columns={"productSCat_id"}),
 *      @Index(name="product_display_area_productSSCat_id", columns={"productSSCat_id"})
 * })
 * @ORM\HasLifecycleCallbacks()
 * @ORM\Entity(repositoryClass="Admin\AdminBundle\Entity\ProductDisplayAreaRepository")
 */
like image 33
Fahim Avatar answered Oct 22 '22 16:10

Fahim