"RuntimeError: can't modify frozen ActiveRecord::Relation" in beta5 #402

Closed
elado opened this Issue Dec 27, 2012 · 3 comments

Projects

None yet

2 participants

@elado
elado commented Dec 27, 2012

In beta5, If an ActiveRecord::Relation is passed to the decorator (and not an array) there's an error:

RuntimeError: can't modify frozen ActiveRecord::Relation
# models/product.rb

class Product < ActiveRecord::Base
  attr_accessible :name
end


# decorators/product_decorator.rb

class ProductDecorator < Draper::Decorator
  decorates :product
end

# console

Product.create!(name: "Hello")
Product.create!(name: "World")

ProductDecorator.decorate_collection(Product.first(2)).count # => 2

ProductDecorator.decorate_collection(Product.limit(2)).count # => Error

Backtrace:

from ~/.rvm/gems/ruby-1.9.3-p327/gems/activerecord-3.2.9/lib/active_record/relation.rb:475:in `eager_loading?'
from ~/.rvm/gems/ruby-1.9.3-p327/gems/activerecord-3.2.9/lib/active_record/relation.rb:171:in `exec_queries'
from ~/.rvm/gems/ruby-1.9.3-p327/gems/activerecord-3.2.9/lib/active_record/relation.rb:160:in `block in to_a'
from ~/.rvm/gems/ruby-1.9.3-p327/gems/activerecord-3.2.9/lib/active_record/explain.rb:33:in `logging_query_plan'
from ~/.rvm/gems/ruby-1.9.3-p327/gems/activerecord-3.2.9/lib/active_record/relation.rb:159:in `to_a'
from ~/.rvm/gems/ruby-1.9.3-p327/gems/activerecord-3.2.9/lib/active_record/relation/delegation.rb:6:in `map'
from ~/.rvm/gems/ruby-1.9.3-p327/gems/draper-1.0.0.beta5/lib/draper/collection_decorator.rb:29:in `decorated_collection'
from ~/.rvm/gems/ruby-1.9.3-p327/gems/draper-1.0.0.beta5/lib/draper/collection_decorator.rb:12:in `count'
from (irb):10
from ~/.rvm/gems/ruby-1.9.3-p327/gems/railties-3.2.9/lib/rails/commands/console.rb:47:in `start'
from ~/.rvm/gems/ruby-1.9.3-p327/gems/railties-3.2.9/lib/rails/commands/console.rb:8:in `start'
from ~/.rvm/gems/ruby-1.9.3-p327/gems/railties-3.2.9/lib/rails/commands.rb:41:in `<top (required)>'
from script/rails:6:in `require'
from script/rails:6:in `<main>'
@steveklabnik
Member

Could you try HEAD for me? I think 9eb9fc9 fixes this.

@elado
elado commented Dec 27, 2012

Yep, seems to work! Thanks!

@steveklabnik
Member

Awesome 🤘.

I plan on doing another release as soon as we figure out what's up with #391.

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