使用lower函数创建Symfony数据库索引

5
如何在Doctrine中声明一个postgresql索引,例如: CREATE INDEX index_name_city_hotel ON booking_hotels(lower(name) text_pattern_ops, city_hotel, cc1)
我已经尝试过了,但好像无法使用lower()函数。 由于lower函数的原因,这是行不通的:
indexes={
@ORM\Index(name="index_name_city_hotel", columns={"lower(name) text_pattern_ops", "city_hotel", "cc1"})

thanks in advance for your help.


我会使用“NONE”策略(http://docs.doctrine-project.org/projects/doctrine-orm/en/latest/reference/basic-mapping.html#identifier-generation-strategies),并在预持久化事件函数中生成所需的ID。 - Veve
1个回答

0

尝试使用https://github.com/intaro/custom-index-bundle

<?php

namespace Acme\MyBundle\Entity;

use Doctrine\ORM\Mapping as ORM;
use Intaro\CustomIndexBundle\Annotations as CustomIndexAnnotation

/**
 * @ORM\Table(name="my_entity")
 * @ORM\Entity()
 * @CustomIndexAnnotation\CustomIndexes(indexes={
 *     @CustomIndexAnnotation\CustomIndex(columns="my_property1"),
 *     @CustomIndexAnnotation\CustomIndex(columns={"lower(my_property1)", "lower(my_property2)"})
 * })
 */
class MyEntity
{
    /**
     * @ORM\Column(type="string", length=256)
     */
    protected $myProperty1;

    /**
     * @ORM\Column(type="string", length=256)
     */
    protected $myProperty2;
}

网页内容由stack overflow 提供, 点击上面的
可以查看英文原文,
原文链接