Skip to content

Instantly share code, notes, and snippets.

@stormsilver
Last active August 29, 2015 14:16
Show Gist options
  • Save stormsilver/cd413ed30c6ec5328e6f to your computer and use it in GitHub Desktop.
Save stormsilver/cd413ed30c6ec5328e6f to your computer and use it in GitHub Desktop.
Rails 4.2.1 polymorphic belongs_to regression where query is nil
unless File.exist?('Gemfile')
File.write('Gemfile', <<-GEMFILE)
source 'https://rubygems.org'
gem 'rails', '4.2.1.rc2'
# gem 'rails', '4.2.0'
gem 'sqlite3'
GEMFILE
system 'bundle'
end
require 'bundler'
Bundler.setup(:default)
require 'active_record'
require 'minitest/autorun'
require 'logger'
# This connection will do for database-independent bug reports.
ActiveRecord::Base.establish_connection(adapter: 'sqlite3', database: ':memory:')
ActiveRecord::Base.logger = Logger.new(STDOUT)
ActiveRecord::Schema.define do
create_table :posts, force: true do |t|
end
create_table :comments, force: true do |t|
t.integer :thing_id
t.string :thing_type
end
end
class Post < ActiveRecord::Base
end
class Comment < ActiveRecord::Base
belongs_to :thing, polymorphic: true
end
class BugTest < Minitest::Test
def test_association_stuff
l = Post.new
puts Comment.where(thing: l).count
puts Comment.where(thing: nil).count
end
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment