class ActiveFedora::Reflection::MacroReflection
def belongs_to?
def belongs_to? macro == :belongs_to end
def build_association(*options)
Returns a new, unsaved instance of the associated class. +options+ will
def build_association(*options) klass.new(*options) end
def class_name
Returns the class name for the macro.
def class_name @class_name ||= options[:class_name] || derive_class_name end
def collection?
association. Returns +true+ if the +macro+ is either +has_many+ or
Returns whether or not this association reflection is for a collection
def collection? @collection end
def derive_class_name
def derive_class_name class_name = name.to_s.camelize class_name = class_name.singularize if collection? class_name end
def derive_foreign_key
def derive_foreign_key if belongs_to? "#{name}_id" elsif has_and_belongs_to_many? "#{name.to_s.singularize}_ids" elsif options[:as] "#{options[:as]}_id" elsif inverse_of && inverse_of.collection? "#{options[:inverse_of].to_s.singularize}_ids" else # This works well if this is a has_many that is the inverse of a belongs_to, but it isn't correct for a has_many that is the invers of a has_and_belongs_to_many active_fedora.name.foreign_key end end
def has_and_belongs_to_many?
def has_and_belongs_to_many? macro == :has_and_belongs_to_many end
def has_many?
def has_many? macro == :has_many end
def initialize(macro, name, options, active_fedora)
def initialize(macro, name, options, active_fedora) @macro, @name, @options, @active_fedora = macro, name, options, active_fedora @automatic_inverse_of = nil end
def klass
a new association object. Use +build_association+ or +create_association+
Note: Do not call +klass.new+ or +klass.create+ to instantiate
# => Book
Author.reflect_on_association(:books).klass
end
has_many :books
class Author < ActiveRecord::Base
Returns the target association's class.
def klass @klass ||= class_name.constantize end