ActiveRecord::Associations::BelongsToAssociation does not properly proxy replace #6231

steveklabnik opened this Issue May 9, 2012 · 1 comment


None yet

2 participants


Two very simple models:

class Album < ActiveRecord::Base

class User < ActiveRecord::Base
  has_many :albums
$ rails c                                                                   
Loading development environment (Rails 3.2.2)
1.9.3p125 :001 > User.first.albums
 => [#<Album id: 4, user_id: 1, created_at: "2012-05-09 19:16:51", updated_at: "2012-05-09 19:16:51">] 

1.9.3p125 :002 > User.first.albums.replace []
 => nil 

Expected return of this:

1.9.3p125 :003 > [].replace [1]
 => [1] 

This leads to a bug in Draper, where when you try to create a HashWithIndifferentAccess, the incorrect replace leads to a nil rather than an empty array.

I'm not sure why this happens. The last line is = record, so the argument should be returned.

@drogus drogus closed this in e2a070c May 17, 2012
drogus commented May 17, 2012

Just for the record, the second commit is for 3-2-stable, so it will be included in next release.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment