'How to create table index with Doctrine and PHP Attributes

Here is the code with PHP annotations

/**
 * @ORM\Table(name="telegram_accounts", schema="users", indexes={
 *      @ORM\Index(name="subscriber_notification_idx", columns={"subscriber_notification"}, options={"where": "subscriber_notification = TRUE"}),
 *      @ORM\Index(name="rename_notification_idx", columns={"rename_notification"}, options={"where": "rename_notification = TRUE"}),
 * })
 * @ORM\Entity(repositoryClass="Skobkin\Bundle\PointToolsBundle\Repository\Telegram\AccountRepository")
 * @ORM\HasLifecycleCallbacks()
 */
class Account

I tried to use PHP Attributes but I cant figure out the correct syntax:

#[ORM\Table(name="telegram_accounts", schema="users", indexes: [
      ORM\Index(name: "subscriber_notification_idx", columns:["subscriber_notification"], options=["where" => "subscriber_notification = TRUE"]),
      ORM\Index(name: "rename_notification_idx", columns: ["rename_notification"], options:["where" => "rename_notification = TRUE"])
])]
#[ORM\Entity(repositoryClass: "Skobkin\Bundle\PointToolsBundle\Repository\Telegram\AccountRepository"]
#[ORM\HasLifecycleCallbacks]
 */
class Account

But this does not work.

How do I insert ORM\Index into the indexes array of ORM\Table attribute?



Solution 1:[1]

Ok, turns out that with attributes the syntax moved to separate attribute:

#[ORM\Table(name: "telegram_accounts", schema: "users")]
#[ORM\Index(name: "subscriber_notification_idx", columns: ["subscriber_notification"], options: ["where" => "subscriber_notification = TRUE"])]
#[ORM\Index(name: "rename_notification_idx", columns: ["rename_notification"], options: ["where" => "rename_notification = TRUE"])]
#[ORM\Entity(repositoryClass: "Skobkin\Bundle\PointToolsBundle\Repository\Telegram\AccountRepository"]
#[ORM\HasLifecycleCallbacks]

Sources

This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.

Source: Stack Overflow

Solution Source
Solution 1 michnovka