当分配给关联的对象类型不正确时引发此错误。
class Ticket < ActiveRecord::Base
has_many :patches
end
class Patch < ActiveRecord::Base
belongs_to :ticket
end
# Comments are not patches, this assignment raises AssociationTypeMismatch.
@ticket.patches << Comment.new(content: "Please attach tests to your patch.")