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}\")\nif !association.nil?\nassociation.each do |r|\nr.save(true) if r.new_record?\nend\n\nif association.updated?\nself[\"\#{reflection.primary_key_name}\"] = association.collect{|r| r.id}\nend\nend\n"
end
end