php - symfony用较低的函数创建数据库索引

标签 php symfony doctrine-orm postgresql-9.4

如何在 Doctrine 中声明 postgresql 的索引,例如: 在 booking_hotels 上创建索引 index_name_city_hotel(lower(name) text_pattern_ops, city_hotel, cc1)

我已经尝试过,但似乎不可能使用 lower() 函数。 由于功能较低,这不起作用:

indexes={
@ORM\Index(name="index_name_city_hotel", columns={"lower(name) text_pattern_ops", "city_hotel", "cc1"})

预先感谢您的帮助。

最佳答案

尝试使用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;
}

关于php - symfony用较低的函数创建数据库索引,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/41591379/

相关文章:

php - 使用 jquery 解析 json 不起作用

php - Magento:无效的方法Mage_Bundle_Block_Catalog_Product_View_Type_Bundle_Option_Radio

php - WooCommerce 'remove_action' 在 'init' Hook 中不起作用

php - 将应用程序中的所有 css 合并到一个 css 文件中是个好主意吗?

php - Symfony2 - 学说异常 : class used in the discriminator map does not exist

php - __autoload 检测并包含接口(interface)

php - Symfony2 显示 "A token was not found in the SecurityContext"而不是我的 AuthenticationException

html - 从 Twig 模板生成 pdf 文件

sql - Doctrine 查询 - 忽略空格

php - Doctrine 返回 null 代替 EntityNotFoundException