module ActiveFedora::Reflection::ClassMethods
def add_reflection(name, reflection)
def add_reflection(name, reflection) # FIXME this is where the problem with association_spec is caused (key is string now) self.reflections = self.reflections.merge(name => reflection) end
def child_resource_reflections
def child_resource_reflections reflections.select { |_, reflection| reflection.kind_of?(AssociationReflection) && reflection.macro == :contains } end
def create_reflection(macro, name, options, active_fedora)
def create_reflection(macro, name, options, active_fedora) klass = case macro when :has_many, :belongs_to, :has_and_belongs_to_many, :contains, :directly_contains, :directly_contains_one, :indirectly_contains AssociationReflection when :rdf, :singular_rdf RDFPropertyReflection end reflection = klass.new(macro, name, options, active_fedora) add_reflection name, reflection reflection end
def outgoing_reflections
def outgoing_reflections reflections.select { |_, reflection| reflection.kind_of? RDFPropertyReflection } end
def reflect_on_all_autosave_associations
def reflect_on_all_autosave_associations reflections.values.select { |reflection| reflection.options[:autosave] } end
def reflect_on_association(association)
Invoice.reflect_on_association(:line_items).macro # returns :has_many
Account.reflect_on_association(:owner) # returns the owner AssociationReflection
Returns the AssociationReflection object for the +association+ (use the symbol).
def reflect_on_association(association) val = reflections[association].is_a?(AssociationReflection) ? reflections[association] : nil unless val # When a has_many is paired with a has_and_belongs_to_many the assocation will have a plural name association = association.to_s.pluralize.to_sym val = reflections[association].is_a?(AssociationReflection) ? reflections[association] : nil end val end
def reflections
Account.reflections
Invoice.reflections
Example:
Returns a hash containing all AssociationReflection objects for the current class.
def reflections read_inheritable_attribute(:reflections) || write_inheritable_attribute(:reflections, {}) end