E
E
EVOSandru62014-12-25 04:02:49
Yii
EVOSandru6, 2014-12-25 04:02:49

How to execute ORDER BY RAND LIMIT 5 query in Yii without using CDbCriteria?

Good afternoon.
It is necessary to get several records from the table in random order. At the same time, it is desirable to retain the ability to access relations through relations
1 . For example Product::model()->findAll ...
, what next? This method is interesting.
I would like to get an object-oriented model
2. Is it possible to achieve an object-oriented model using cdbcriteria?

Answer the question

In order to leave comments, you need to log in

2 answer(s)
T
twixoff, 2014-12-25
@EVOSandru6

Product::model()->findAll(  
    array(  
        "condition" => "active=1 AND test_category_id=3",  
        "order" => "rand()",  
        "limit" => 5,  
        ) 
);

_
_ _, 2014-12-25
@AMar4enko

findAll() can take CDbCriteria as an argument

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question