How does ActiveRecord::Relation get added to Rails' models and why does each model have individual Relation class?

前端 未结 2 1286
感动是毒
感动是毒 2021-01-25 05:13

Suppose I have a Rails model: class Project < ActiveRecord::Base

In the Rails console:

> Project.all
=> #

        
2条回答
  •  无人共我
    2021-01-25 05:25

    There are actually two questions you are asking:

    1. How does it work?
    2. Why is it like that? (What for?)

    @arieljuod has already given you some explanations and a link.

    However the second question is still unanswered.

    There is another similar question exists which I hope will help you find all the answers:

    How can an ActiveRecord::Relation object call class methods

    It looks like the two questions (by the link and yours one) answer each other )

    Take a look at @nikita-shilnikov's answer. Good luck in your investigation!

提交回复
热议问题