在active_record/base.rb,module ActiveRecord
方法,您可以看到這樣的代碼:瞭解代表和範圍的Rails中
delegate :find, :first, :last, :all, :destroy, :destroy_all, :exists?, :delete,
:delete_all, :update, :update_all, :to => :scoped
讓我們first
方法,所以我認爲first
方法委託給scoped
方法,然後scoped
應從數據庫返回第一條記錄。但scoped
只是匿名scope
,目前的建設如何做它的工作?
與此同時,動態方法如何工作,如find_by_name
,find_all_by_name_and_colour
?
謝謝