Skip to content

How does a Model have access to a class method like where? #5858

Closed Answered by jamis
AlvesJorge asked this question in Q&A
Discussion options

You must be logged in to vote

Mongoid makes very heavy use of delegation and metaprogramming. It also uses ActiveSupport::Concern (from Rails) so that you can define class methods in a module that get applied when the module is included.

Looking specifically at the #where method will give you a bit of a taste of just how convoluted this gets. :)

  • The #where method is defined on the Mongoid::Criteria class: here
  • The #where method is included in the set of methods that Mongoid::Criteria::Queryable::Selectable declares as "forwardable", here
  • Mongoid::Document includes Mongoid::Composable (here), which extends Mongoid::Findable (here).
  • Mongoid::Findable delegates those forwardable defined in Mongoid::Criteria::Queryable::…

Replies: 2 comments

Comment options

You must be logged in to vote
0 replies
Answer selected by AlvesJorge
Comment options

You must be logged in to vote
0 replies
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Category
Q&A
Labels
None yet
2 participants