# File lib/big_record/br_associations.rb, line 57 def belongs_to_big_record(association_id, options = {}) if options.include?(:class_name) && !options.include?(:foreign_key) ::ActiveSupport::Deprecation.warn( "The inferred foreign_key name will change in Rails 2.0 to use the association name instead of its class name when they differ. When using :class_name in belongs_to, use the :foreign_key option to explicitly set the key name to avoid problems in the transition.", caller) end reflection = create_belongs_to_big_record_reflection(association_id, options) if reflection.options[:polymorphic] association_accessor_methods_big_record(reflection, BelongsToPolymorphicAssociation) module_eval do before_save association = instance_variable_get("@#{reflection.name}") if association && association.target if association.new_record? association.save(true) end if association.updated? self["#{reflection.primary_key_name}"] = association.id self["#{reflection.options[:foreign_type]}"] = association.class.base_class.name.to_s end end end else association_accessor_methods_big_record(reflection, BelongsToAssociation) association_constructor_method_big_record(:build, reflection, BelongsToAssociation) association_constructor_method_big_record(:create, reflection, BelongsToAssociation) module_eval do before_save association = instance_variable_get("@#{reflection.name}") if !association.nil? if association.new_record? association.save(true) end if association.updated? self["#{reflection.primary_key_name}"] = association.id end end end end if options[:counter_cache] cache_column = options[:counter_cache] == true ? "#{self.to_s.underscore.pluralize}_count" : options[:counter_cache] module_eval( "after_create '#{reflection.name}.class.increment_counter(\"#{cache_column}\", #{reflection.primary_key_name})" + " unless #{reflection.name}.nil?'" ) module_eval( "before_destroy '#{reflection.name}.class.decrement_counter(\"#{cache_column}\", #{reflection.primary_key_name})" + " unless #{reflection.name}.nil?'" ) end end
# File lib/big_record/br_associations.rb, line 125 def belongs_to_many(association_id, options = {}) if options.include?(:class_name) && !options.include?(:foreign_key) ::ActiveSupport::Deprecation.warn( "The inferred foreign_key name will change in Rails 2.0 to use the association name instead of its class name when they differ. When using :class_name in belongs_to, use the :foreign_key option to explicitly set the key name to avoid problems in the transition.", caller) end reflection = create_belongs_to_many_reflection(association_id, options) association_accessor_methods_big_record(reflection, BelongsToManyAssociation) association_constructor_method_big_record(:build, reflection, BelongsToManyAssociation) association_constructor_method_big_record(:create, reflection, BelongsToManyAssociation) module_eval do before_save association = instance_variable_get("@#{reflection.name}") if !association.nil? association.each do |r| r.save(true) if r.new_record? end if association.updated? self["#{reflection.primary_key_name}"] = association.collect{|r| r.id} end end end end
# File lib/big_record/br_associations.rb, line 156 def has_and_belongs_to_many_big_records(association_id, options = {}, &extension) reflection = create_has_and_belongs_to_many_big_records_reflection(association_id, options, &extension) collection_accessor_methods(reflection, HasAndBelongsToManyAssociation) # Don't use a before_destroy callback since users' before_destroy # callbacks will be executed after the association is wiped out. old_method = "destroy_without_habtm_shim_for_#{reflection.name}" class_eval alias_method :#{old_method}, :destroy_without_callbacks def destroy_without_callbacks #{reflection.name}.clear #{old_method} end add_association_callbacks(reflection.name, options) end
# File lib/big_record/br_associations.rb, line 18 def has_many_big_records(association_id, options = {}, &extension) reflection = create_has_many_big_records_reflection(association_id, options, &extension) configure_dependency_for_has_many(reflection) if options[:through] collection_reader_method(reflection, HasManyThroughAssociation) else add_association_callbacks(reflection.name, reflection.options) collection_accessor_methods(reflection, HasManyAssociation) end end
# File lib/big_record/br_associations.rb, line 34 def has_one_big_record(association_id, options = {}) reflection = create_has_one_big_record_reflection(association_id, options) module_eval do after_save association = instance_variable_get("@#{reflection.name}") if !association.nil? && (new_record? || association.new_record? || association["#{reflection.primary_key_name}"] != id) association["#{reflection.primary_key_name}"] = id association.save(true) end end association_accessor_methods_big_record(reflection, HasOneAssociation) association_constructor_method_big_record(:build, reflection, HasOneAssociation) association_constructor_method_big_record(:create, reflection, HasOneAssociation) configure_dependency_for_has_one(reflection) end
Generated with the Darkfish Rdoc Generator 2.