我是一名PHP开发人员,学习Ruby on Rails的优点,我喜欢ActiveRecord,我注意到一些非常有趣的东西,这就是ActiveRecord方法检测方法链结束执行查询的方式.
@person = Person.where(name: 'Jason').where(age: 26)
# In my humble imagination I'd think that each where() executes a database query
# But in reality, it doesn't until the last method in the chain
Run Code Online (Sandbox Code Playgroud)
这个巫术是如何运作的?