You can modify the scope with additional order and where scopes here. ActiveRelation is really cool like that

At any time you can debug your query scope with .to_sql