如何在 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/