[RAILS] I think it's okay to write joins etc. in the scope

It is subjective. I think there are pros and cons, but I would be grateful if you could give us various opinions.

background

I saw this code.

class Hoge
  scope :with_active_fuga, -> { merge(Fuga.active) }

With this, the scope alone does not work. You have to add joins (: fuga) etc. But this joins (: fuga) etc.

I was wondering, so I stopped and thought about it.

Reasons for deciding that it is okay to write in scope

By the way

Since there are some people who create processing in the class without using scope for narrowing down where joins etc. occur, ** "narrowing down = scope" is not always **.

Recommended Posts

I think it's okay to write joins etc. in the scope
I want to write JSP in Emacs more easily than the default.
I want to get the value in Ruby
I didn't know what to write in Maven's scope so I looked it up
I was addicted to the NoSuchMethodError in Cloud Endpoints
I want to embed any TraceId in the log
[Active Admin] I want to specify the scope of the collection to be displayed in select_box
I tried to implement the Euclidean algorithm in Java
I want to set the conditions to be displayed in collection_check_boxes
What I did in the version upgrade from Ruby 2.5.2 to 2.7.1
I want to transition to the same screen in the saved state
I wanted to think I understood Elm's custom types in Java
I want to simplify the conditional if-else statement in Java
I tried to summarize the words that I often see in docker-compose.yml
What if I write a finally clause in the try-with-resources syntax?
I tried to illuminate the Christmas tree in a life game
I tried to sort the data in descending order, ascending order / Rails
I tried to write code like a type declaration in Ruby
What I did in the migration from Spring Boot 1.4 series to 2.0 series
I want to display the images under assets/images in the production environment
What I did in the migration from Spring Boot 1.5 series to 2.0 series
I want to remove the top margin in Grouped UITableView (swift)
[Java] I want to perform distinct with the key in the object
I got stuck trying to write a where in clause in ActiveRecord
[Android] I want to get the listener from the button in ListView
How to write the view when Vue is introduced in Rails?
Pass the i18n locale to JavaScript
[Rails] How to write in Japanese
I tried to explain the method
The story I wanted to unzip
[Ruby] I want to output only the odd-numbered characters in the character string
I summarized the points to note when using resources and resources in combination
[Introduction to Java] I tried to summarize the knowledge that I think is essential
I tried to solve the tribonacci sequence problem in Ruby, with recursion.
I called the COTOHA API parser 100 times in Java to measure performance.
I want to get the IP address when connecting to Wi-Fi in Java
I thought about the best way to create a ValueObject in Ruby
I tried to make full use of the CPU core in Ruby
I want to display an error message when registering in the database
I was addicted to unit testing with the buffer operator in RxJava
[Ruby] I tried to summarize the methods that frequently appear in paiza
[Ruby] I tried to summarize the methods that frequently appear in paiza ②