Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

eager loading versions fails #386

Closed
bvogel opened this issue Jun 23, 2014 · 3 comments
Closed

eager loading versions fails #386

bvogel opened this issue Jun 23, 2014 · 3 comments
Milestone

Comments

@bvogel
Copy link

bvogel commented Jun 23, 2014

I try to visualize the previous versions of an object in a view:

MyObject.includes(:versions)

Doing this with Rails 4.0.5, Ruby 2.1.2 and PaperTrail 3.0.2 will lead to either of the following errors:

undefined method `version_class_name' for nil:NilClass

undefined method `version_class_name' for #<ActiveRecord::Associations::JoinDependency::JoinAssociation:0x007f89c5021830>

We use custom versioning classes defined through:

class MyObject < ActiveRecord::Base
  has_paper_trail class_name: 'MyObjectVersion'

and MyObjectVersion defined as

 class MyObjectVersion < PaperTrail::Version
  self.table_name = 'my_object_versions'

Stacktrace:

NoMethodError - undefined method `version_class_name' for nil:NilClass:
  paper_trail (3.0.2) lib/paper_trail/has_paper_trail.rb:64:in `block in has_paper_trail'
  activerecord (4.0.5) lib/active_record/associations/preloader/association.rb:96:in `reflection_scope'
  activerecord (4.0.5) lib/active_record/associations/preloader/association.rb:103:in `build_scope'
  activerecord (4.0.5) lib/active_record/associations/preloader/collection_association.rb:9:in `build_scope'
  activerecord (4.0.5) lib/active_record/associations/preloader/association.rb:28:in `scope'
  activerecord (4.0.5) lib/active_record/associations/preloader/association.rb:32:in `records_for'
  activerecord (4.0.5) lib/active_record/associations/preloader/association.rb:80:in `block in associated_records_by_owner'
  activerecord (4.0.5) lib/active_record/associations/preloader/association.rb:80:in `associated_records_by_owner'
  activerecord (4.0.5) lib/active_record/associations/preloader/collection_association.rb:13:in `preload'
  activerecord (4.0.5) lib/active_record/associations/preloader/association.rb:19:in `run'
  activerecord (4.0.5) lib/active_record/associations/preloader.rb:129:in `block (2 levels) in preload_one'
  activerecord (4.0.5) lib/active_record/associations/preloader.rb:128:in `block in preload_one'
  activerecord (4.0.5) lib/active_record/associations/preloader.rb:127:in `preload_one'
  activerecord (4.0.5) lib/active_record/associations/preloader.rb:104:in `preload'
  activerecord (4.0.5) lib/active_record/associations/preloader.rb:93:in `block in run'
  activerecord (4.0.5) lib/active_record/associations/preloader.rb:93:in `run'
  activerecord (4.0.5) lib/active_record/relation.rb:590:in `block in exec_queries'
  activerecord (4.0.5) lib/active_record/relation.rb:589:in `exec_queries'
  activerecord (4.0.5) lib/active_record/relation.rb:471:in `load'
  activerecord (4.0.5) lib/active_record/relation.rb:220:in `to_a'
  bullet (4.10.0) lib/bullet/active_record4.rb:10:in `to_a'
  activerecord (4.0.5) lib/active_record/relation/finder_methods.rb:316:in `find_take'
  activerecord (4.0.5) lib/active_record/relation/finder_methods.rb:66:in `take'
  activerecord (4.0.5) lib/active_record/relation/finder_methods.rb:283:in `find_one'
  activerecord (4.0.5) lib/active_record/relation/finder_methods.rb:269:in `find_with_ids'
  activerecord (4.0.5) lib/active_record/relation/finder_methods.rb:36:in `find'
  activerecord-deprecated_finders (1.0.3) lib/active_record/deprecated_finders/relation.rb:122:in `find'
  app/controllers/my_objects_controller.rb:16:in `show'
  actionpack (4.0.5) lib/action_controller/metal/implicit_render.rb:4:in `send_action'
  actionpack (4.0.5) lib/abstract_controller/base.rb:189:in `process_action'
  actionpack (4.0.5) lib/action_controller/metal/rendering.rb:10:in `process_action'
  actionpack (4.0.5) lib/abstract_controller/callbacks.rb:18:in `block in process_action'
  activesupport (4.0.5) lib/active_support/callbacks.rb:453:in `_run__3164819652734084574__process_action__callbacks'
  activesupport (4.0.5) lib/active_support/callbacks.rb:80:in `run_callbacks'
  actionpack (4.0.5) lib/abstract_controller/callbacks.rb:17:in `process_action'
  actionpack (4.0.5) lib/action_controller/metal/rescue.rb:29:in `process_action'
  actionpack (4.0.5) lib/action_controller/metal/instrumentation.rb:31:in `block in process_action'
  activesupport (4.0.5) lib/active_support/notifications.rb:159:in `block in instrument'
  activesupport (4.0.5) lib/active_support/notifications/instrumenter.rb:20:in `instrument'
  activesupport (4.0.5) lib/active_support/notifications.rb:159:in `instrument'
  actionpack (4.0.5) lib/action_controller/metal/instrumentation.rb:30:in `process_action'
  actionpack (4.0.5) lib/action_controller/metal/params_wrapper.rb:250:in `process_action'
  activerecord (4.0.5) lib/active_record/railties/controller_runtime.rb:18:in `process_action'
  actionpack (4.0.5) lib/abstract_controller/base.rb:136:in `process'
  actionpack (4.0.5) lib/abstract_controller/rendering.rb:44:in `process'
  rack-mini-profiler (0.9.1) lib/mini_profiler/profiling_methods.rb:108:in `block in profile_method'
  actionpack (4.0.5) lib/action_controller/metal.rb:195:in `dispatch'
  actionpack (4.0.5) lib/action_controller/metal/rack_delegation.rb:13:in `dispatch'
  actionpack (4.0.5) lib/action_controller/metal.rb:231:in `block in action'
  actionpack (4.0.5) lib/action_dispatch/routing/route_set.rb:80:in `dispatch'
  actionpack (4.0.5) lib/action_dispatch/routing/route_set.rb:48:in `call'
  actionpack (4.0.5) lib/action_dispatch/journey/router.rb:71:in `block in call'
  actionpack (4.0.5) lib/action_dispatch/journey/router.rb:59:in `call'
  actionpack (4.0.5) lib/action_dispatch/routing/route_set.rb:674:in `call'
  bullet (4.10.0) lib/bullet/rack.rb:12:in `call'
  rack (1.5.2) lib/rack/etag.rb:23:in `call'
  rack (1.5.2) lib/rack/conditionalget.rb:25:in `call'
  rack (1.5.2) lib/rack/head.rb:11:in `call'
  remotipart (1.2.1) lib/remotipart/middleware.rb:27:in `call'
  actionpack (4.0.5) lib/action_dispatch/middleware/params_parser.rb:27:in `call'
  actionpack (4.0.5) lib/action_dispatch/middleware/flash.rb:241:in `call'
  rack (1.5.2) lib/rack/session/abstract/id.rb:225:in `context'
  rack (1.5.2) lib/rack/session/abstract/id.rb:220:in `call'
  actionpack (4.0.5) lib/action_dispatch/middleware/cookies.rb:486:in `call'
  activerecord (4.0.5) lib/active_record/query_cache.rb:36:in `call'
  activerecord (4.0.5) lib/active_record/connection_adapters/abstract/connection_pool.rb:626:in `call'
  actionpack (4.0.5) lib/action_dispatch/middleware/callbacks.rb:29:in `block in call'
  activesupport (4.0.5) lib/active_support/callbacks.rb:373:in `_run__2618913376504265873__call__callbacks'
  activesupport (4.0.5) lib/active_support/callbacks.rb:80:in `run_callbacks'
  actionpack (4.0.5) lib/action_dispatch/middleware/callbacks.rb:27:in `call'
  actionpack (4.0.5) lib/action_dispatch/middleware/reloader.rb:64:in `call'
  actionpack (4.0.5) lib/action_dispatch/middleware/remote_ip.rb:76:in `call'
  airbrake (4.0.0) lib/airbrake/rails/middleware.rb:13:in `call'
  better_errors (1.1.0) lib/better_errors/middleware.rb:84:in `protected_app_call'
  better_errors (1.1.0) lib/better_errors/middleware.rb:79:in `better_errors_call'
  better_errors (1.1.0) lib/better_errors/middleware.rb:56:in `call'
  actionpack (4.0.5) lib/action_dispatch/middleware/debug_exceptions.rb:17:in `call'
  actionpack (4.0.5) lib/action_dispatch/middleware/show_exceptions.rb:30:in `call'
  railties (4.0.5) lib/rails/rack/logger.rb:38:in `call_app'
  railties (4.0.5) lib/rails/rack/logger.rb:20:in `block in call'
  activesupport (4.0.5) lib/active_support/tagged_logging.rb:68:in `block in tagged'
  activesupport (4.0.5) lib/active_support/tagged_logging.rb:26:in `tagged'
  activesupport (4.0.5) lib/active_support/tagged_logging.rb:68:in `tagged'
  railties (4.0.5) lib/rails/rack/logger.rb:20:in `call'
  quiet_assets (1.0.3) lib/quiet_assets.rb:23:in `call_with_quiet_assets'
  actionpack (4.0.5) lib/action_dispatch/middleware/request_id.rb:21:in `call'
  rack (1.5.2) lib/rack/methodoverride.rb:21:in `call'
  rack (1.5.2) lib/rack/runtime.rb:17:in `call'
  activesupport (4.0.5) lib/active_support/cache/strategy/local_cache.rb:83:in `call'
  rack (1.5.2) lib/rack/lock.rb:17:in `call'
  actionpack (4.0.5) lib/action_dispatch/middleware/static.rb:64:in `call'
  rack (1.5.2) lib/rack/sendfile.rb:112:in `call'
  rack-mini-profiler (0.9.1) lib/mini_profiler/profiler.rb:300:in `call'
  airbrake (4.0.0) lib/airbrake/user_informer.rb:16:in `_call'
  airbrake (4.0.0) lib/airbrake/user_informer.rb:12:in `call'
  railties (4.0.5) lib/rails/engine.rb:511:in `call'
  railties (4.0.5) lib/rails/application.rb:97:in `call'
  rack (1.5.2) lib/rack/lock.rb:17:in `call'
  rack (1.5.2) lib/rack/content_length.rb:14:in `call'
  rack (1.5.2) lib/rack/handler/webrick.rb:60:in `service'
  webrick (1.3.1) lib/webrick/httpserver.rb:138:in `service'
  webrick (1.3.1) lib/webrick/httpserver.rb:94:in `run'
  webrick (1.3.1) lib/webrick/server.rb:191:in `block in start_thread'
@batter batter added this to the 3.0.3 milestone Jun 23, 2014
@batter
Copy link
Collaborator

batter commented Jun 23, 2014

This is fixed in 3.0.3, which I'm trying to release by the end of this week. Until then, please bundle the gem from source to fix this issue:

# Gemfile
gem 'paper_trail', github: 'airblade/paper_trail'

For the record, I believe this was fixed by 87751ac and ee338a5; the adjustments made for #347.

@batter batter closed this as completed Jun 23, 2014
batter added a commit that referenced this issue Jun 24, 2014
@batter
Copy link
Collaborator

batter commented Jun 27, 2014

@bvogel - I just pushed version 3.0.3 to Rubygems so you should just now be able to install that and run with it

@bswinnerton
Copy link

👍 muchos gracias.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants