How to convert this request to yii request?
I want this Sql command to be converted to yii cactivedataprovider format so that I can serve dataprovider with these criteria.
SELECT *
FROM (
SELECT (
CASE WHEN product_name LIKE '%nokia%'
THEN 1
ELSE 0
END +
CASE WHEN product_name LIKE '%lumia%'
THEN 1
ELSE 0
END +
CASE WHEN product_name LIKE '%800%'
THEN 1
ELSE 0
END
) AS numMatches, product_name
FROM Production
) AS t
WHERE numMatches >0
ORDER BY numMatches DESC
+3
source to share
1 answer
Your comment about the need ActiveDataProvider
is most likely incorrect, most Yii widgets need an instance CDataProvider
that is both SQLDataProvider and ActiveDataProvider. If you really need active record models, you can select active record models via SQL with:
$models = MyModel::model()->findAllBySql($sql);
And then use them in the data provider like this:
$data = CArrayDataProvider($models);
+3
source to share