M
M
Maxim Timofeev2015-11-08 14:08:24
Yii
Maxim Timofeev, 2015-11-08 14:08:24

What is the easiest way to get a random value in Yii2?

Let's say we have a request:

$model = Post::find()->andWhere(['fignya'=>'1'])->all();

How is it easier and less resource-intensive to get one random record?

Answer the question

In order to leave comments, you need to log in

1 answer(s)
A
Alexander Gubarev, 2015-11-08
@webinar

ORDER BY RAND is a resource-intensive thing, I recommend that you familiarize yourself with MySQL optimization: ORDER BY RAND ()

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question