check_validity(reflection)
private
TODO: These checks should probably be moved into the Reflection, and we
should not be
redefining the options[:join_table] value - instead we should define a
reflection.join_table method.
# File activerecord/lib/active_record/associations/builder/has_and_belongs_to_many.rb, line 31
def check_validity(reflection)
if reflection.association_foreign_key == reflection.foreign_key
raise ActiveRecord::HasAndBelongsToManyAssociationForeignKeyNeeded.new(reflection)
end
reflection.options[:join_table] ||= join_table_name(
model.send(:undecorated_table_name, model.to_s),
model.send(:undecorated_table_name, reflection.class_name)
)
if model.connection.supports_primary_key? && (model.connection.primary_key(reflection.options[:join_table]) rescue false)
raise ActiveRecord::HasAndBelongsToManyAssociationWithPrimaryKeyError.new(reflection)
end
end