Programming Phoenix briefly mentions that functions which only build queries - generally ones that take an
Ecto.Queryable in first position and return one as well - be put in the schema file.
This makes sense to me as queries tend to be strongly coupled to the schema definitions, by using literal field names and associations.
OTOH, anybody’s who has worked on a long-lived app that uses ActiveRecord knows how lengthy the list of
named_scopes can get. Is there a point where a schema file is “too long”?
One approach I feel decent about to keep this under control is to relocate one-off query-building functions from the schema file to a private function in the context, to avoid sending readers off to another file to understand what’s happening.
Thoughts? Other options? Horror stories?