Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to bypass default_scope?

I have a User model that has the following default_scope:

default_scope where(account_id: Account.current_account.id)

If I call User.all I always get a result based on the current account.

In some cases, for admin purposes, I'd like to bypass that scope and see all the users in the system regardless of the account.

Is there a way to do this?

like image 328
Nathan Avatar asked Apr 01 '12 22:04

Nathan


1 Answers

Yes, with unscoped.

User.unscoped.all
like image 179
Dejan Simic Avatar answered Sep 29 '22 07:09

Dejan Simic