How can I get the entire list of areas in ActiveRecord 3.x

I am using ActiveRecord with Rails 3.

I have identified areas in my model. How can I get a list of all areas of this model?

I used to use Model.scopes

OR Is it possible to determine the scope or not? Something like Model.scope_defined?("scope_name")

Thanks in advance.

+6
source share
1 answer

You can see if the scope is defined or not.

 Model.send(:valid_scope_name?, :scope_name) 

it will return true if it exists, and nil if it is not.

Should you check the source code valid_scope_name? , you will see that you can just test it with respond_to? and then avoid the registration part.

 Model.respond_to?(scope_name, true) 
+3
source

Source: https://habr.com/ru/post/926376/


All Articles