Created
March 2, 2015 21:21
-
-
Save stormsilver/6245b43838e77f5c6636 to your computer and use it in GitHub Desktop.
rails update_all does not include joins
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
unless File.exist?('Gemfile') | |
File.write('Gemfile', <<-GEMFILE) | |
source 'https://rubygems.org' | |
gem 'rails', github: 'rails/rails' | |
gem 'arel', github: 'rails/arel' | |
# gem 'rails', github: 'rails/rails', branch: '4-2-stable' | |
# gem 'rails', '4.2.1.rc2' | |
# gem 'rails', '4.2.0' | |
# gem 'rails', '4.1.9' | |
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| | |
t.integer :author_id | |
t.string :author_stuff | |
end | |
create_table :authors do |t| | |
t.string :stuff | |
end | |
end | |
class Post < ActiveRecord::Base | |
belongs_to :author | |
end | |
class Author < ActiveRecord::Base | |
end | |
class BugTest < Minitest::Test | |
def test_association_stuff | |
Post.joins("authors on authors.id = posts.author_id").update_all('author_stuff = authors.stuff') | |
end | |
end |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment