我想创建一个索引列表,以加快搜索。
示例:
#[ORMEntity(repositoryClass: SettingRepository::class)]
#[ORMTable(name: '`tr_setting`', indexes: [
new ORMIndex(columns: ['code'], name: 'idx_setting_code')
])]
class Setting
{
#[ORMColumn(type: 'string', length: 15)]
private ?string $code;
#[ORMColumn(type: 'text')]
private string $content;
#[ORMId]
#[ORMGeneratedValue]
#[ORMColumn(type: 'integer')]
private ?int $id;
// Getter and setter...
}
当我使用DoctrineBundle迁移时,文件被生成,但是索引被忽略…
// ....
final class Version20220719140604 extends AbstractMigration
{
public function up(Schema $schema): void
{
// this up() migration is auto-generated, please modify it to your needs
$this->addSql('CREATE SEQUENCE "tr_setting_id_seq" INCREMENT BY 1 MINVALUE 1 START 1');
$this->addSql('CREATE TABLE "tr_setting" (id INT NOT NULL, code VARCHAR(15) NOT NULL, content TEXT NOT NULL, PRIMARY KEY(id))');
}
对于其他项目,我已经使用注释而不是属性。
我仔细阅读了这个答案,但它没有帮助我。
我在PHP8.1.8, doctrine/orm 2.12.3, doctrine-migrations: 3.2, postgresql: 13
我的索引应该用这样的语法声明:
#[
ORMEntity(repositoryClass: SettingRepository::class),
ORMTable(name: '`tr_setting`'),
ORMIndex(columns: ['code'], name: 'idx_setting_code'),
]
或者这个
#[ORMEntity(repositoryClass: SettingRepository::class)]
#[ORMTable(name: '`tr_setting`')]
#[ORMIndex(columns: ['code'], name: 'idx_setting_code')]