Consider how #order works - it adds additional order to scope instead of replacing it. To replace, we use #reorder.
We can’t change this behavior on #select (making #select be additive and adding #reselect to be replacing) because it’d break existing APIs. But we could at least add a method like #add_select or #append select.
In our code, we have a lot of places that go like this:
memberships.includes(:user).select(“memberships.*, users.email”)
It’s even worse for complex joins, where I need to manually remember every table that would be part of the join (or risk getting attribute missing errors).
What I want is to just add a field to existing select and not break all the normal selects already there:
memberships.includes(:user).add_select(“users.email”)
Naming wise, I’m leaning towards #add_select as opposed to #append_select, because “append” implies order-specific (as opposed to “prepend”) while this should be order-insensitive.
Anyone has an opinion?
Thanks!