-1

Topic: ordering in doctrine.

I want to order car brands and the problem appears when I want to order brands that start with characters such as Š, Đ, Ć, Č or Ž. For example, when I use doctrines orderBy function I get this for my result:
Seat
Škoda
Suzuki.
Notice that Škoda is ordered like it starts with S and not Š.

Successful outcome:

How can I get data to be ordered according to Serbian latin alphabet so I get this result:
Seat
Suzuki
Škoda

Škoda would come after Suzuki cause Suzuki is last one that starts with S and Škoda is first that starts with Š, also Š comes after S in Serbian latin alphabet).

Or if this isn't possible is there any other solution where data wouldn't get mixed when ordered (Š not mixed with S, Č not mixed with C, Ć not mixed with C and so on)
Any help would appreciated.

Tedinoz
  • 5,911
  • 3
  • 25
  • 35

2 Answers2

0

Try to change database collation. Maybe try utf8_bin Because in utf8_general_ci Š and S will be the same

Adil
  • 152
  • 2
  • 8
  • 1
    This worked after droping my table cause doctrine didn't want to make an alter when using command doctrine:schema:update. Thanks! – LudiDinSaSalaša Aug 28 '19 at 17:26
0

You can alter the collation for a particular column by using the options annotation in your entity (see the docs for database support):

class Brand
{
    // ...

    /**
     * @ORM\Column(type="string", length=255, options={"collation":"latin1_general_ci"})
     */
    private $name;
}

This will alter your database, so you'll have to create a migration or update the schema.

msg
  • 7,863
  • 3
  • 14
  • 33