You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Select with block given for has_many association is broken in 5.1.0.beta1 and current master. It doesn't include newly built records. It looks like the regression is caused by #25877.
Steps to reproduce
begin
require "bundler/inline"
rescue LoadError => e
$stderr.puts "Bundler version 1.10 or later is required. Please update your Bundler"
raise e
end
gemfile(true) do
source "https://rubygems.org"
gem "rails", github: "rails/rails"
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 :post_id
end
end
class Post < ActiveRecord::Base
has_many :comments
end
class Comment < ActiveRecord::Base
belongs_to :post
end
class BugTest < Minitest::Test
def test_select
post = Post.create!
post.comments.build
post.comments.build
assert_equal 2, post.comments.size
assert_equal 2, post.comments.select{ true }.size
end
def test_select_with_existing_item
post = Post.create!
post.comments.create!
post.comments.build
post.comments.build
assert_equal 3, post.comments.size
assert_equal 3, post.comments.select{ true }.size
end
end
Expected behavior
Select with block given should select both newly built and existing items.
Actual behavior
Select returns only saved items.
System configuration
Rails version: 5.1.0.beta1
Ruby version: 2.4.0
The text was updated successfully, but these errors were encountered:
kamipo
added a commit
to kamipo/rails
that referenced
this issue
Mar 9, 2017
…association
The `select` in `QueryMethods` is also an enumerable method.
Enumerable methods with block should delegate to `records` on
`CollectionProxy`, not `scope`.
Fixesrails#28348.
Select with block given for has_many association is broken in 5.1.0.beta1 and current master. It doesn't include newly built records. It looks like the regression is caused by #25877.
Steps to reproduce
Expected behavior
Select with block given should select both newly built and existing items.
Actual behavior
Select returns only saved items.
System configuration
Rails version: 5.1.0.beta1
Ruby version: 2.4.0
The text was updated successfully, but these errors were encountered: