From 90171ad833fa15a3030e15b7eb2043e1204d9db0 Mon Sep 17 00:00:00 2001 From: Aaron Patterson Date: Wed, 5 Jan 2011 10:29:06 -0800 Subject: avoid creating so many Arel::Table objects --- .../associations/has_and_belongs_to_many_association.rb | 15 +++++++++------ 1 file changed, 9 insertions(+), 6 deletions(-) diff --git a/activerecord/lib/active_record/associations/has_and_belongs_to_many_association.rb b/activerecord/lib/active_record/associations/has_and_belongs_to_many_association.rb index 3c939d7e85..b18ec23037 100644 --- a/activerecord/lib/active_record/associations/has_and_belongs_to_many_association.rb +++ b/activerecord/lib/active_record/associations/has_and_belongs_to_many_association.rb @@ -2,9 +2,16 @@ module ActiveRecord # = Active Record Has And Belongs To Many Association module Associations class HasAndBelongsToManyAssociation < AssociationCollection #:nodoc: + attr_reader :join_table + + def initialize(owner, reflection) + @join_table_name = reflection.options[:join_table] + @join_table = Arel::Table.new(@join_table_name) + super + end def columns - @reflection.columns(@reflection.options[:join_table], "#{@reflection.options[:join_table]} Columns") + @reflection.columns(@join_table_name, "#{@join_table_name} Columns") end def reset_column_information @@ -12,7 +19,7 @@ module ActiveRecord end def has_primary_key? - @has_primary_key ||= @owner.connection.supports_primary_key? && @owner.connection.primary_key(@reflection.options[:join_table]) + @has_primary_key ||= @owner.connection.supports_primary_key? && @owner.connection.primary_key(@join_table_name) end protected @@ -77,10 +84,6 @@ module ActiveRecord right.create_join(right, right.create_on(condition)) end - def join_table - Arel::Table.new(@reflection.options[:join_table]) - end - def construct_owner_conditions super(join_table) end -- cgit v1.2.3