2004-11-23 20:04:44 -05:00
|
|
|
module ActiveRecord
|
|
|
|
module Reflection # :nodoc:
|
2009-05-28 12:35:36 -04:00
|
|
|
extend ActiveSupport::Concern
|
2004-11-23 20:04:44 -05:00
|
|
|
|
2005-07-10 00:22:08 -04:00
|
|
|
# Reflection allows you to interrogate Active Record classes and objects about their associations and aggregations.
|
2005-10-26 09:05:48 -04:00
|
|
|
# This information can, for example, be used in a form builder that took an Active Record object and created input
|
2004-11-23 20:04:44 -05:00
|
|
|
# fields for all of the attributes depending on their type and displayed the associations to other objects.
|
|
|
|
#
|
|
|
|
# You can find the interface for the AggregateReflection and AssociationReflection classes in the abstract MacroReflection class.
|
|
|
|
module ClassMethods
|
2005-12-02 23:29:55 -05:00
|
|
|
def create_reflection(macro, name, options, active_record)
|
|
|
|
case macro
|
|
|
|
when :has_many, :belongs_to, :has_one, :has_and_belongs_to_many
|
2008-10-04 11:53:13 -04:00
|
|
|
klass = options[:through] ? ThroughReflection : AssociationReflection
|
|
|
|
reflection = klass.new(macro, name, options, active_record)
|
2005-12-02 23:29:55 -05:00
|
|
|
when :composed_of
|
2006-02-25 18:32:24 -05:00
|
|
|
reflection = AggregateReflection.new(macro, name, options, active_record)
|
2005-12-02 23:29:55 -05:00
|
|
|
end
|
2006-02-25 18:32:24 -05:00
|
|
|
write_inheritable_hash :reflections, name => reflection
|
|
|
|
reflection
|
2005-12-02 23:29:55 -05:00
|
|
|
end
|
2008-10-04 11:53:13 -04:00
|
|
|
|
2007-01-05 15:22:41 -05:00
|
|
|
# Returns a hash containing all AssociationReflection objects for the current class
|
|
|
|
# Example:
|
|
|
|
#
|
|
|
|
# Invoice.reflections
|
|
|
|
# Account.reflections
|
|
|
|
#
|
2005-12-02 23:29:55 -05:00
|
|
|
def reflections
|
2007-01-05 15:22:41 -05:00
|
|
|
read_inheritable_attribute(:reflections) || write_inheritable_attribute(:reflections, {})
|
2005-12-02 23:29:55 -05:00
|
|
|
end
|
2008-10-04 11:53:13 -04:00
|
|
|
|
2004-11-23 20:04:44 -05:00
|
|
|
# Returns an array of AggregateReflection objects for all the aggregations in the class.
|
|
|
|
def reflect_on_all_aggregations
|
2005-12-02 23:29:55 -05:00
|
|
|
reflections.values.select { |reflection| reflection.is_a?(AggregateReflection) }
|
2004-11-23 20:04:44 -05:00
|
|
|
end
|
2005-07-10 00:22:08 -04:00
|
|
|
|
2004-11-23 20:04:44 -05:00
|
|
|
# Returns the AggregateReflection object for the named +aggregation+ (use the symbol). Example:
|
2007-01-05 15:22:41 -05:00
|
|
|
#
|
2004-11-23 20:04:44 -05:00
|
|
|
# Account.reflect_on_aggregation(:balance) # returns the balance AggregateReflection
|
2007-01-05 15:22:41 -05:00
|
|
|
#
|
2004-11-23 20:04:44 -05:00
|
|
|
def reflect_on_aggregation(aggregation)
|
2005-12-02 23:29:55 -05:00
|
|
|
reflections[aggregation].is_a?(AggregateReflection) ? reflections[aggregation] : nil
|
2004-11-23 20:04:44 -05:00
|
|
|
end
|
|
|
|
|
2007-11-07 22:37:16 -05:00
|
|
|
# Returns an array of AssociationReflection objects for all the associations in the class. If you only want to reflect on a
|
2008-05-02 09:45:23 -04:00
|
|
|
# certain association type, pass in the symbol (<tt>:has_many</tt>, <tt>:has_one</tt>, <tt>:belongs_to</tt>) for that as the first parameter.
|
2007-01-05 15:22:41 -05:00
|
|
|
# Example:
|
|
|
|
#
|
|
|
|
# Account.reflect_on_all_associations # returns an array of all associations
|
|
|
|
# Account.reflect_on_all_associations(:has_many) # returns an array of all has_many associations
|
|
|
|
#
|
2005-12-27 00:41:23 -05:00
|
|
|
def reflect_on_all_associations(macro = nil)
|
|
|
|
association_reflections = reflections.values.select { |reflection| reflection.is_a?(AssociationReflection) }
|
|
|
|
macro ? association_reflections.select { |reflection| reflection.macro == macro } : association_reflections
|
2004-11-23 20:04:44 -05:00
|
|
|
end
|
2005-07-10 00:22:08 -04:00
|
|
|
|
2007-11-07 22:37:16 -05:00
|
|
|
# Returns the AssociationReflection object for the named +association+ (use the symbol). Example:
|
2007-01-05 15:22:41 -05:00
|
|
|
#
|
2004-11-23 20:04:44 -05:00
|
|
|
# Account.reflect_on_association(:owner) # returns the owner AssociationReflection
|
2006-02-28 15:13:37 -05:00
|
|
|
# Invoice.reflect_on_association(:line_items).macro # returns :has_many
|
2007-01-05 15:22:41 -05:00
|
|
|
#
|
2004-11-23 20:04:44 -05:00
|
|
|
def reflect_on_association(association)
|
2005-12-02 23:29:55 -05:00
|
|
|
reflections[association].is_a?(AssociationReflection) ? reflections[association] : nil
|
2004-11-23 20:04:44 -05:00
|
|
|
end
|
2009-01-31 20:44:30 -05:00
|
|
|
|
|
|
|
# Returns an array of AssociationReflection objects for all associations which have <tt>:autosave</tt> enabled.
|
|
|
|
def reflect_on_all_autosave_associations
|
|
|
|
reflections.values.select { |reflection| reflection.options[:autosave] }
|
|
|
|
end
|
2004-11-23 20:04:44 -05:00
|
|
|
end
|
|
|
|
|
2005-07-10 00:22:08 -04:00
|
|
|
|
|
|
|
# Abstract base class for AggregateReflection and AssociationReflection that describes the interface available for both of
|
2004-11-23 20:04:44 -05:00
|
|
|
# those classes. Objects of AggregateReflection and AssociationReflection are returned by the Reflection::ClassMethods.
|
|
|
|
class MacroReflection
|
|
|
|
attr_reader :active_record
|
2007-01-14 07:08:44 -05:00
|
|
|
|
2005-02-27 12:18:35 -05:00
|
|
|
def initialize(macro, name, options, active_record)
|
|
|
|
@macro, @name, @options, @active_record = macro, name, options, active_record
|
2004-11-23 20:04:44 -05:00
|
|
|
end
|
2005-07-10 00:22:08 -04:00
|
|
|
|
2008-04-04 23:52:58 -04:00
|
|
|
# Returns the name of the macro. For example, <tt>composed_of :balance, :class_name => 'Money'</tt> will return
|
|
|
|
# <tt>:balance</tt> or for <tt>has_many :clients</tt> it will return <tt>:clients</tt>.
|
2004-11-23 20:04:44 -05:00
|
|
|
def name
|
|
|
|
@name
|
|
|
|
end
|
2005-07-10 00:22:08 -04:00
|
|
|
|
2008-04-04 23:52:58 -04:00
|
|
|
# Returns the macro type. For example, <tt>composed_of :balance, :class_name => 'Money'</tt> will return <tt>:composed_of</tt>
|
|
|
|
# or for <tt>has_many :clients</tt> will return <tt>:has_many</tt>.
|
2005-02-27 12:18:35 -05:00
|
|
|
def macro
|
|
|
|
@macro
|
|
|
|
end
|
2005-07-10 00:22:08 -04:00
|
|
|
|
2008-04-04 23:52:58 -04:00
|
|
|
# Returns the hash of options used for the macro. For example, it would return <tt>{ :class_name => "Money" }</tt> for
|
|
|
|
# <tt>composed_of :balance, :class_name => 'Money'</tt> or +{}+ for <tt>has_many :clients</tt>.
|
2004-11-23 20:04:44 -05:00
|
|
|
def options
|
|
|
|
@options
|
|
|
|
end
|
2005-07-10 00:22:08 -04:00
|
|
|
|
2008-05-02 09:45:23 -04:00
|
|
|
# Returns the class for the macro. For example, <tt>composed_of :balance, :class_name => 'Money'</tt> returns the Money
|
|
|
|
# class and <tt>has_many :clients</tt> returns the Client class.
|
2007-01-14 07:08:44 -05:00
|
|
|
def klass
|
|
|
|
@klass ||= class_name.constantize
|
|
|
|
end
|
|
|
|
|
2008-04-04 23:52:58 -04:00
|
|
|
# Returns the class name for the macro. For example, <tt>composed_of :balance, :class_name => 'Money'</tt> returns <tt>'Money'</tt>
|
|
|
|
# and <tt>has_many :clients</tt> returns <tt>'Client'</tt>.
|
2005-12-02 23:29:55 -05:00
|
|
|
def class_name
|
2007-01-14 07:08:44 -05:00
|
|
|
@class_name ||= options[:class_name] || derive_class_name
|
2005-12-02 23:29:55 -05:00
|
|
|
end
|
|
|
|
|
2008-04-04 23:52:58 -04:00
|
|
|
# Returns +true+ if +self+ and +other_aggregation+ have the same +name+ attribute, +active_record+ attribute,
|
|
|
|
# and +other_aggregation+ has an options hash assigned to it.
|
2004-11-23 20:04:44 -05:00
|
|
|
def ==(other_aggregation)
|
2008-08-15 16:51:57 -04:00
|
|
|
other_aggregation.kind_of?(self.class) && name == other_aggregation.name && other_aggregation.options && active_record == other_aggregation.active_record
|
2004-11-23 20:04:44 -05:00
|
|
|
end
|
2007-01-14 07:08:44 -05:00
|
|
|
|
2008-06-26 21:47:30 -04:00
|
|
|
def sanitized_conditions #:nodoc:
|
|
|
|
@sanitized_conditions ||= klass.send(:sanitize_sql, options[:conditions]) if options[:conditions]
|
|
|
|
end
|
|
|
|
|
2008-10-04 12:41:27 -04:00
|
|
|
# Returns +true+ if +self+ is a +belongs_to+ reflection.
|
|
|
|
def belongs_to?
|
|
|
|
macro == :belongs_to
|
|
|
|
end
|
|
|
|
|
2007-01-14 07:08:44 -05:00
|
|
|
private
|
|
|
|
def derive_class_name
|
|
|
|
name.to_s.camelize
|
|
|
|
end
|
2004-11-23 20:04:44 -05:00
|
|
|
end
|
|
|
|
|
|
|
|
|
|
|
|
# Holds all the meta-data about an aggregation as it was specified in the Active Record class.
|
|
|
|
class AggregateReflection < MacroReflection #:nodoc:
|
|
|
|
end
|
|
|
|
|
|
|
|
# Holds all the meta-data about an association as it was specified in the Active Record class.
|
|
|
|
class AssociationReflection < MacroReflection #:nodoc:
|
2008-09-06 13:43:14 -04:00
|
|
|
# Returns the target association's class:
|
|
|
|
#
|
|
|
|
# class Author < ActiveRecord::Base
|
|
|
|
# has_many :books
|
|
|
|
# end
|
|
|
|
#
|
|
|
|
# Author.reflect_on_association(:books).klass
|
|
|
|
# # => Book
|
|
|
|
#
|
|
|
|
# <b>Note:</b> do not call +klass.new+ or +klass.create+ to instantiate
|
|
|
|
# a new association object. Use +build_association+ or +create_association+
|
|
|
|
# instead. This allows plugins to hook into association object creation.
|
2004-11-23 20:04:44 -05:00
|
|
|
def klass
|
2005-12-02 23:29:55 -05:00
|
|
|
@klass ||= active_record.send(:compute_type, class_name)
|
2005-04-18 14:49:34 -04:00
|
|
|
end
|
2005-07-10 00:22:08 -04:00
|
|
|
|
2010-03-14 18:46:03 -04:00
|
|
|
def initialize(macro, name, options, active_record)
|
|
|
|
super
|
|
|
|
@collection = [:has_many, :has_and_belongs_to_many].include?(macro)
|
|
|
|
end
|
|
|
|
|
2008-09-06 13:43:14 -04:00
|
|
|
# Returns a new, unsaved instance of the associated class. +options+ will
|
|
|
|
# be passed to the class's constructor.
|
|
|
|
def build_association(*options)
|
|
|
|
klass.new(*options)
|
|
|
|
end
|
|
|
|
|
|
|
|
# Creates a new instance of the associated class, and immediates saves it
|
|
|
|
# with ActiveRecord::Base#save. +options+ will be passed to the class's
|
|
|
|
# creation method. Returns the newly created object.
|
|
|
|
def create_association(*options)
|
|
|
|
klass.create(*options)
|
|
|
|
end
|
|
|
|
|
|
|
|
# Creates a new instance of the associated class, and immediates saves it
|
|
|
|
# with ActiveRecord::Base#save!. +options+ will be passed to the class's
|
|
|
|
# creation method. If the created record doesn't pass validations, then an
|
|
|
|
# exception will be raised.
|
|
|
|
#
|
|
|
|
# Returns the newly created object.
|
|
|
|
def create_association!(*options)
|
|
|
|
klass.create!(*options)
|
|
|
|
end
|
|
|
|
|
2005-04-18 14:49:34 -04:00
|
|
|
def table_name
|
|
|
|
@table_name ||= klass.table_name
|
2004-11-23 20:04:44 -05:00
|
|
|
end
|
|
|
|
|
2008-01-05 09:58:28 -05:00
|
|
|
def quoted_table_name
|
|
|
|
@quoted_table_name ||= klass.quoted_table_name
|
|
|
|
end
|
|
|
|
|
2005-12-02 23:29:55 -05:00
|
|
|
def primary_key_name
|
2007-01-14 07:08:44 -05:00
|
|
|
@primary_key_name ||= options[:foreign_key] || derive_primary_key_name
|
2005-12-02 23:29:55 -05:00
|
|
|
end
|
2007-01-14 07:08:44 -05:00
|
|
|
|
2005-12-02 23:29:55 -05:00
|
|
|
def association_foreign_key
|
|
|
|
@association_foreign_key ||= @options[:association_foreign_key] || class_name.foreign_key
|
|
|
|
end
|
|
|
|
|
2006-03-04 14:42:41 -05:00
|
|
|
def counter_cache_column
|
|
|
|
if options[:counter_cache] == true
|
2008-12-31 04:43:13 -05:00
|
|
|
"#{active_record.name.demodulize.underscore.pluralize}_count"
|
2006-03-04 14:42:41 -05:00
|
|
|
elsif options[:counter_cache]
|
|
|
|
options[:counter_cache]
|
|
|
|
end
|
|
|
|
end
|
|
|
|
|
2009-01-16 14:04:19 -05:00
|
|
|
def columns(tbl_name, log_msg)
|
|
|
|
@columns ||= klass.connection.columns(tbl_name, log_msg)
|
|
|
|
end
|
|
|
|
|
|
|
|
def reset_column_information
|
|
|
|
@columns = nil
|
|
|
|
end
|
|
|
|
|
2008-10-04 11:53:13 -04:00
|
|
|
def check_validity!
|
2009-05-01 11:01:13 -04:00
|
|
|
check_validity_of_inverse!
|
|
|
|
end
|
|
|
|
|
|
|
|
def check_validity_of_inverse!
|
2009-11-29 00:46:09 -05:00
|
|
|
unless options[:polymorphic]
|
|
|
|
if has_inverse? && inverse_of.nil?
|
|
|
|
raise InverseOfAssociationNotFoundError.new(self)
|
|
|
|
end
|
2009-05-01 11:01:13 -04:00
|
|
|
end
|
2008-10-04 11:53:13 -04:00
|
|
|
end
|
|
|
|
|
|
|
|
def through_reflection
|
|
|
|
false
|
|
|
|
end
|
|
|
|
|
2008-10-04 12:41:27 -04:00
|
|
|
def through_reflection_primary_key_name
|
|
|
|
end
|
|
|
|
|
2008-10-04 11:53:13 -04:00
|
|
|
def source_reflection
|
|
|
|
nil
|
|
|
|
end
|
|
|
|
|
2009-05-01 11:01:13 -04:00
|
|
|
def has_inverse?
|
|
|
|
!@options[:inverse_of].nil?
|
|
|
|
end
|
|
|
|
|
|
|
|
def inverse_of
|
|
|
|
if has_inverse?
|
|
|
|
@inverse_of ||= klass.reflect_on_association(options[:inverse_of])
|
|
|
|
end
|
|
|
|
end
|
|
|
|
|
2009-11-29 00:46:09 -05:00
|
|
|
def polymorphic_inverse_of(associated_class)
|
|
|
|
if has_inverse?
|
2009-12-28 08:13:33 -05:00
|
|
|
if inverse_relationship = associated_class.reflect_on_association(options[:inverse_of])
|
|
|
|
inverse_relationship
|
|
|
|
else
|
|
|
|
raise InverseOfAssociationNotFoundError.new(self, associated_class)
|
|
|
|
end
|
2009-11-29 00:46:09 -05:00
|
|
|
end
|
|
|
|
end
|
|
|
|
|
2009-12-31 08:03:04 -05:00
|
|
|
# Returns whether or not this association reflection is for a collection
|
|
|
|
# association. Returns +true+ if the +macro+ is one of +has_many+ or
|
|
|
|
# +has_and_belongs_to_many+, +false+ otherwise.
|
2010-01-08 15:44:06 -05:00
|
|
|
def collection?
|
|
|
|
@collection
|
2009-12-31 08:03:04 -05:00
|
|
|
end
|
|
|
|
|
2010-01-03 15:45:08 -05:00
|
|
|
# Returns whether or not the association should be validated as part of
|
|
|
|
# the parent's validation.
|
|
|
|
#
|
|
|
|
# Unless you explicitely disable validation with
|
|
|
|
# <tt>:validate => false</tt>, it will take place when:
|
|
|
|
#
|
|
|
|
# * you explicitely enable validation; <tt>:validate => true</tt>
|
|
|
|
# * you use autosave; <tt>:autosave => true</tt>
|
|
|
|
# * the association is a +has_many+ association
|
|
|
|
def validate?
|
|
|
|
!options[:validate].nil? ? options[:validate] : (options[:autosave] == true || macro == :has_many)
|
|
|
|
end
|
|
|
|
|
2010-04-03 12:54:15 -04:00
|
|
|
def dependent_conditions(record, base_class, extra_conditions)
|
2010-04-03 01:33:57 -04:00
|
|
|
dependent_conditions = []
|
|
|
|
dependent_conditions << "#{primary_key_name} = #{record.send(name).send(:owner_quoted_id)}"
|
|
|
|
dependent_conditions << "#{options[:as]}_type = '#{base_class.name}'" if options[:as]
|
|
|
|
dependent_conditions << klass.send(:sanitize_sql, options[:conditions]) if options[:conditions]
|
2010-04-03 12:54:15 -04:00
|
|
|
dependent_conditions << extra_conditions if extra_conditions
|
2010-04-03 01:33:57 -04:00
|
|
|
dependent_conditions = dependent_conditions.collect {|where| "(#{where})" }.join(" AND ")
|
|
|
|
dependent_conditions = dependent_conditions.gsub('@', '\@')
|
|
|
|
dependent_conditions
|
|
|
|
end
|
|
|
|
|
2008-10-04 11:53:13 -04:00
|
|
|
private
|
|
|
|
def derive_class_name
|
|
|
|
class_name = name.to_s.camelize
|
2010-01-08 15:44:06 -05:00
|
|
|
class_name = class_name.singularize if collection?
|
2008-10-04 11:53:13 -04:00
|
|
|
class_name
|
|
|
|
end
|
|
|
|
|
|
|
|
def derive_primary_key_name
|
2008-10-04 12:41:27 -04:00
|
|
|
if belongs_to?
|
2008-10-04 11:53:13 -04:00
|
|
|
"#{name}_id"
|
|
|
|
elsif options[:as]
|
|
|
|
"#{options[:as]}_id"
|
|
|
|
else
|
|
|
|
active_record.name.foreign_key
|
|
|
|
end
|
|
|
|
end
|
|
|
|
end
|
|
|
|
|
|
|
|
# Holds all the meta-data about a :through association as it was specified in the Active Record class.
|
|
|
|
class ThroughReflection < AssociationReflection #:nodoc:
|
|
|
|
# Gets the source of the through reflection. It checks both a singularized and pluralized form for <tt>:belongs_to</tt> or <tt>:has_many</tt>.
|
|
|
|
# (The <tt>:tags</tt> association on Tagging below.)
|
|
|
|
#
|
|
|
|
# class Post < ActiveRecord::Base
|
|
|
|
# has_many :taggings
|
|
|
|
# has_many :tags, :through => :taggings
|
|
|
|
# end
|
|
|
|
#
|
|
|
|
def source_reflection
|
|
|
|
@source_reflection ||= source_reflection_names.collect { |name| through_reflection.klass.reflect_on_association(name) }.compact.first
|
|
|
|
end
|
|
|
|
|
2008-05-09 05:38:02 -04:00
|
|
|
# Returns the AssociationReflection object specified in the <tt>:through</tt> option
|
|
|
|
# of a HasManyThrough or HasOneThrough association. Example:
|
|
|
|
#
|
|
|
|
# class Post < ActiveRecord::Base
|
|
|
|
# has_many :taggings
|
|
|
|
# has_many :tags, :through => :taggings
|
|
|
|
# end
|
|
|
|
#
|
|
|
|
# tags_reflection = Post.reflect_on_association(:tags)
|
|
|
|
# taggings_reflection = tags_reflection.through_reflection
|
|
|
|
#
|
2006-03-18 17:38:49 -05:00
|
|
|
def through_reflection
|
2008-10-04 11:53:13 -04:00
|
|
|
@through_reflection ||= active_record.reflect_on_association(options[:through])
|
2006-03-18 17:38:49 -05:00
|
|
|
end
|
|
|
|
|
2008-05-02 09:45:23 -04:00
|
|
|
# Gets an array of possible <tt>:through</tt> source reflection names:
|
2006-03-19 02:14:48 -05:00
|
|
|
#
|
2008-05-02 09:45:23 -04:00
|
|
|
# [:singularized, :pluralized]
|
2007-01-05 15:22:41 -05:00
|
|
|
#
|
2006-03-19 02:14:48 -05:00
|
|
|
def source_reflection_names
|
2006-03-24 09:46:17 -05:00
|
|
|
@source_reflection_names ||= (options[:source] ? [options[:source]] : [name.to_s.singularize, name]).collect { |n| n.to_sym }
|
2006-03-18 19:53:24 -05:00
|
|
|
end
|
|
|
|
|
|
|
|
def check_validity!
|
2008-10-04 11:53:13 -04:00
|
|
|
if through_reflection.nil?
|
|
|
|
raise HasManyThroughAssociationNotFoundError.new(active_record.name, self)
|
|
|
|
end
|
2007-03-13 01:23:18 -04:00
|
|
|
|
2008-10-04 11:53:13 -04:00
|
|
|
if source_reflection.nil?
|
|
|
|
raise HasManyThroughSourceAssociationNotFoundError.new(self)
|
|
|
|
end
|
|
|
|
|
|
|
|
if options[:source_type] && source_reflection.options[:polymorphic].nil?
|
|
|
|
raise HasManyThroughAssociationPointlessSourceTypeError.new(active_record.name, self, source_reflection)
|
|
|
|
end
|
|
|
|
|
|
|
|
if source_reflection.options[:polymorphic] && options[:source_type].nil?
|
|
|
|
raise HasManyThroughAssociationPolymorphicError.new(active_record.name, self, source_reflection)
|
|
|
|
end
|
|
|
|
|
2009-08-09 15:53:22 -04:00
|
|
|
unless [:belongs_to, :has_many, :has_one].include?(source_reflection.macro) && source_reflection.options[:through].nil?
|
2008-10-04 11:53:13 -04:00
|
|
|
raise HasManyThroughSourceAssociationMacroError.new(self)
|
2006-03-18 19:53:24 -05:00
|
|
|
end
|
2009-05-01 11:01:13 -04:00
|
|
|
|
|
|
|
check_validity_of_inverse!
|
2006-03-18 19:53:24 -05:00
|
|
|
end
|
|
|
|
|
2008-10-04 12:41:27 -04:00
|
|
|
def through_reflection_primary_key
|
|
|
|
through_reflection.belongs_to? ? through_reflection.klass.primary_key : through_reflection.primary_key_name
|
|
|
|
end
|
|
|
|
|
|
|
|
def through_reflection_primary_key_name
|
|
|
|
through_reflection.primary_key_name if through_reflection.belongs_to?
|
|
|
|
end
|
|
|
|
|
2004-11-23 20:04:44 -05:00
|
|
|
private
|
2007-01-14 07:08:44 -05:00
|
|
|
def derive_class_name
|
|
|
|
# get the class_name of the belongs_to association of the through reflection
|
2008-10-04 11:53:13 -04:00
|
|
|
options[:source_type] || source_reflection.class_name
|
2004-11-23 20:04:44 -05:00
|
|
|
end
|
|
|
|
end
|
|
|
|
end
|
2005-07-10 00:22:08 -04:00
|
|
|
end
|