php - How to create ActiveRecord query for this MySQL query? -
i got mysql query, how can write activerecord?
select * `sel_posts` `login_id` = 22 or 23 or 24 ... (this ids array $ifollow) order `datetime` desc limit 0 , 20
first of all, it's better replace or
in
in where
part.
assuming model named selpost
, here how can activequery
:
$models = selpost::find() ->where(['login_id' => $ifollow]) ->orderby(['datetime' => sort_desc]) ->limit(20) ->all();
where
smart enough automatically add in
operator in case of $ifollow
being array.
official documentation:
Comments
Post a Comment