Skip to content

Instantly share code, notes, and snippets.

@sinsoku
Created July 9, 2021 09:47
Show Gist options
  • Save sinsoku/e60f55074b6f37376eb07c2700673762 to your computer and use it in GitHub Desktop.
Save sinsoku/e60f55074b6f37376eb07c2700673762 to your computer and use it in GitHub Desktop.
# frozen_string_literal: true
require "bundler/inline"
gemfile(true) do
source "https://rubygems.org"
git_source(:github) { |repo| "https://github.com/#{repo}.git" }
# Activate the gem you are reporting the issue against.
# gem "activerecord", "6.0.4"
gem "activerecord", "6.1.4"
gem "sqlite3"
end
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 :x_post_id
end
end
class Post < ActiveRecord::Base
has_many :comments
end
class Comment < ActiveRecord::Base
belongs_to :post, foreign_key: :x_post_id
end
class BugTest < Minitest::Test
def test_association_stuff
post = Post.create!
Comment.create!(x_post_id: post.id)
comments = Comment.eager_load(:post).select(:id)
assert_equal post.id, comments.first.x_post_id
# 6.1.4
#=> ActiveModel::MissingAttributeError: missing attribute: x_post_id
end
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment