提交 68d10565 编写于 作者: D David Heinemeier Hansson

Fixed that has_and_belongs_to_many would generate bad sql when naming...

Fixed that has_and_belongs_to_many would generate bad sql when naming conventions differed from using vanilla "id" everywhere [RedTerror]

git-svn-id: http://svn-commit.rubyonrails.org/rails/trunk@152 5ecf4fe2-1ee6-0310-87b1-e25e094e27de
上级 c80f974f
*CVS*
* Fixed that has_and_belongs_to_many would generate bad sql when naming conventions differed from using vanilla "id" everywhere [RedTerror]
* Added a better exception for when a type column is used in a table without the intention of triggering single-table inheritance. Example:
ActiveRecord::SubclassNotFound: The single-table inheritance mechanism failed to locate the subclass: 'bad_class!'.
......
......@@ -3,16 +3,16 @@ module Associations
class HasAndBelongsToManyAssociation < AssociationCollection #:nodoc:
def initialize(owner, association_name, association_class_name, association_class_primary_key_name, join_table, options)
super(owner, association_name, association_class_name, association_class_primary_key_name, options)
@association_foreign_key = options[:association_foreign_key] || Inflector.underscore(Inflector.demodulize(association_class_name)) + "_id"
association_table_name = options[:table_name] || @association_class.table_name(association_class_name)
@join_table = join_table
@order = options[:order] || "t.#{@owner.class.primary_key}"
@order = options[:order] || "t.#{@association_class.primary_key}"
interpolate_sql_options!(options, :finder_sql, :delete_sql)
@finder_sql = options[:finder_sql] ||
"SELECT t.*, j.* FROM #{association_table_name} t, #{@join_table} j " +
"WHERE t.#{@owner.class.primary_key} = j.#{@association_foreign_key} AND " +
"WHERE t.#{@association_class.primary_key} = j.#{@association_foreign_key} AND " +
"j.#{association_class_primary_key_name} = #{@owner.quoted_id} " +
(options[:conditions] ? " AND " + options[:conditions] : "") + " " +
"ORDER BY #{@order}"
......@@ -105,4 +105,4 @@ def delete_records(records)
end
end
end
end
\ No newline at end of file
end
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册