Giest
Giest

Reputation: 495

Yii2: OrderBy with CASE (Order manual)

How can I make a manual ordering?

My table:

table
id | name
1 | inactive
2 | active
3 | archived

And the result has to be this order: active, inactive, archived How can I make in Yii2?

Table::find()
->OrderBy(***);

Upvotes: 1

Views: 600

Answers (1)

Gordon Linoff
Gordon Linoff

Reputation: 1270573

In MySQL, you would use the field() function:

order by field(name, 'inactive', 'active', 'archived')

You can probably implement this in Yii2 using the same function.

Upvotes: 3

Related Questions