Base
AggregateReflection 與 AssociationReflection 的類別。AggregateReflection 與 AssociationReflection 的物件是由 Reflection::ClassMethods
回傳。
方法
屬性
[R] | active_record | |
[R] | name | 傳回巨集的名稱。
|
[R] | options | 傳回巨集使用的選項雜湊。
|
[R] | scope |
類別公開方法
new(name, scope, options, active_record) 連結
來源:顯示 | 在 GitHub 上
# File activerecord/lib/active_record/reflection.rb, line 388 def initialize(name, scope, options, active_record) super() @name = name @scope = scope @options = normalize_options(options) @active_record = active_record @klass = options[:anonymous_class] @plural_name = active_record.pluralize_table_names ? name.to_s.pluralize : name.to_s end
執行個體公開方法
==(other_aggregation) 連結
如果 self
與 other_aggregation
具有相同的 name
屬性和 active_record
屬性,且 other_aggregation
已指定選項雜湊,則傳回 true
。
來源:顯示 | 在 GitHub 上
# File activerecord/lib/active_record/reflection.rb, line 440 def ==(other_aggregation) super || other_aggregation.kind_of?(self.class) && name == other_aggregation.name && !other_aggregation.options.nil? && active_record == other_aggregation.active_record end
autosave=(autosave) 連結
來源:顯示 | 在 GitHub 上
# File activerecord/lib/active_record/reflection.rb, line 399 def autosave=(autosave) @options[:autosave] = autosave parent_reflection = self.parent_reflection if parent_reflection parent_reflection.autosave = autosave end end
compute_class(name) 連結
來源:顯示 | 在 GitHub 上
# File activerecord/lib/active_record/reflection.rb, line 434 def compute_class(name) name.constantize end
klass() 連結
傳回巨集的類別。
composed_of :balance, class_name: 'Money'
傳回 Money 類別 has_many :clients
傳回 Client 類別
class Company < ActiveRecord::Base
has_many :clients
end
Company.reflect_on_association(:clients).klass
# => Client
注意:請勿呼叫 klass.new
或 klass.create
來實體化新的關聯物件。請改用 build_association
或 create_association
。這讓外掛可以掛入關聯物件建立。
來源:顯示 | 在 GitHub 上
# File activerecord/lib/active_record/reflection.rb, line 422 def klass @klass ||= _klass(class_name) end