togglepro / pundit-resources

Integrate Pundit policies with jsonapi-resources
MIT License
46 stars 39 forks source link

has_many relations causing error #1

Closed intothefire closed 8 years ago

intothefire commented 8 years ago

Hi,

Trying to implement this in a project, but running in to a problem with has_many relationships.

On a resource with has_many :pages I get the below error.

This error is occurring when doing a simple read, not trying to update the related records.

Full Stack Trace:

Internal Server Error: Page(id: integer, name: string, survey_id: integer, page_type: , created_at: datetime, updated_at: datetime, properties: jsonb, sub_head: text, position: integer) is not an ActiveRecord::Relation /Users/cnorman/.rvm/gems/ruby-2.3.1@ISGPDR/gems/activerecord-5.0.0.rc1/lib/active_record/relation/spawn_methods.rb:48:in merge!' /Users/cnorman/.rvm/gems/ruby-2.3.1@ISGPDR/gems/activerecord-5.0.0.rc1/lib/active_record/relation/spawn_methods.rb:34:inmerge' /Users/cnorman/Documents/Development/ISG/PDR/pundit-resources/lib/pundit/resource.rb:59:in records_for' /Users/cnorman/.rvm/gems/ruby-2.3.1@ISGPDR/bundler/gems/jsonapi-resources-e81e4043597c/lib/jsonapi/resource.rb:880:inblock (2 levels) in _add_relationship' /Users/cnorman/.rvm/gems/ruby-2.3.1@ISGPDR/bundler/gems/jsonapi-resources-e81e4043597c/lib/jsonapi/resource.rb:935:in public_send' /Users/cnorman/.rvm/gems/ruby-2.3.1@ISGPDR/bundler/gems/jsonapi-resources-e81e4043597c/lib/jsonapi/resource.rb:935:inblock (2 levels) in _add_relationship' /Users/cnorman/.rvm/gems/ruby-2.3.1@ISGPDR/bundler/gems/jsonapi-resources-e81e4043597c/lib/jsonapi/resource_serializer.rb:209:in public_send' /Users/cnorman/.rvm/gems/ruby-2.3.1@ISGPDR/bundler/gems/jsonapi-resources-e81e4043597c/lib/jsonapi/resource_serializer.rb:209:inblock in relationships_hash' /Users/cnorman/.rvm/gems/ruby-2.3.1@ISGPDR/bundler/gems/jsonapi-resources-e81e4043597c/lib/jsonapi/resource_serializer.rb:203:in each' /Users/cnorman/.rvm/gems/ruby-2.3.1@ISGPDR/bundler/gems/jsonapi-resources-e81e4043597c/lib/jsonapi/resource_serializer.rb:203:ineach_with_object' /Users/cnorman/.rvm/gems/ruby-2.3.1@ISGPDR/bundler/gems/jsonapi-resources-e81e4043597c/lib/jsonapi/resource_serializer.rb:203:in relationships_hash' /Users/cnorman/.rvm/gems/ruby-2.3.1@ISGPDR/bundler/gems/jsonapi-resources-e81e4043597c/lib/jsonapi/resource_serializer.rb:129:inobject_hash' /Users/cnorman/.rvm/gems/ruby-2.3.1@ISGPDR/bundler/gems/jsonapi-resources-e81e4043597c/lib/jsonapi/resource_serializer.rb:108:in process_primary' /Users/cnorman/.rvm/gems/ruby-2.3.1@ISGPDR/bundler/gems/jsonapi-resources-e81e4043597c/lib/jsonapi/resource_serializer.rb:102:inblock in process_primary' /Users/cnorman/.rvm/gems/ruby-2.3.1@ISGPDR/bundler/gems/jsonapi-resources-e81e4043597c/lib/jsonapi/resource_serializer.rb:102:in each' /Users/cnorman/.rvm/gems/ruby-2.3.1@ISGPDR/bundler/gems/jsonapi-resources-e81e4043597c/lib/jsonapi/resource_serializer.rb:102:inprocess_primary' /Users/cnorman/.rvm/gems/ruby-2.3.1@ISGPDR/bundler/gems/jsonapi-resources-e81e4043597c/lib/jsonapi/resource_serializer.rb:46:in serialize_to_hash' /Users/cnorman/.rvm/gems/ruby-2.3.1@ISGPDR/bundler/gems/jsonapi-resources-e81e4043597c/lib/jsonapi/response_document.rb:122:inresults_to_hash' /Users/cnorman/.rvm/gems/ruby-2.3.1@ISGPDR/bundler/gems/jsonapi-resources-e81e4043597c/lib/jsonapi/response_document.rb:11:in contents' /Users/cnorman/.rvm/gems/ruby-2.3.1@ISGPDR/bundler/gems/jsonapi-resources-e81e4043597c/lib/jsonapi/acts_as_resource_controller.rb:154:inrender_results' /Users/cnorman/.rvm/gems/ruby-2.3.1@ISGPDR/bundler/gems/jsonapi-resources-e81e4043597c/lib/jsonapi/acts_as_resource_controller.rb:64:in process_request' /Users/cnorman/.rvm/gems/ruby-2.3.1@ISGPDR/bundler/gems/jsonapi-resources-e81e4043597c/lib/jsonapi/acts_as_resource_controller.rb:13:inindex' /Users/cnorman/.rvm/gems/ruby-2.3.1@ISGPDR/gems/actionpack-5.0.0.rc1/lib/abstract_controller/base.rb:181:in process_action' /Users/cnorman/.rvm/gems/ruby-2.3.1@ISGPDR/gems/actionpack-5.0.0.rc1/lib/action_controller/metal/rendering.rb:30:inprocess_action' /Users/cnorman/.rvm/gems/ruby-2.3.1@ISGPDR/gems/actionpack-5.0.0.rc1/lib/abstract_controller/callbacks.rb:20:in block in process_action' /Users/cnorman/.rvm/gems/ruby-2.3.1@ISGPDR/gems/activesupport-5.0.0.rc1/lib/active_support/callbacks.rb:126:incall' /Users/cnorman/.rvm/gems/ruby-2.3.1@ISGPDR/gems/activesupport-5.0.0.rc1/lib/active_support/callbacks.rb:506:in block (2 levels) in compile' /Users/cnorman/.rvm/gems/ruby-2.3.1@ISGPDR/gems/activesupport-5.0.0.rc1/lib/active_support/callbacks.rb:455:incall' /Users/cnorman/.rvm/gems/ruby-2.3.1@ISGPDR/gems/activesupport-5.0.0.rc1/lib/active_support/callbacks.rb:101:in __run_callbacks__' /Users/cnorman/.rvm/gems/ruby-2.3.1@ISGPDR/gems/activesupport-5.0.0.rc1/lib/active_support/callbacks.rb:750:in_run_process_action_callbacks' /Users/cnorman/.rvm/gems/ruby-2.3.1@ISGPDR/gems/activesupport-5.0.0.rc1/lib/active_support/callbacks.rb:90:inrun_callbacks' /Users/cnorman/.rvm/gems/ruby-2.3.1@ISGPDR/gems/actionpack-5.0.0.rc1/lib/abstract_controller/callbacks.rb:19:inprocess_action' /Users/cnorman/.rvm/gems/ruby-2.3.1@ISGPDR/gems/actionpack-5.0.0.rc1/lib/action_controller/metal/instrumentation.rb:32:inblock in process_action' /Users/cnorman/.rvm/gems/ruby-2.3.1@ISGPDR/gems/activesupport-5.0.0.rc1/lib/active_support/notifications.rb:164:inblock in instrument' /Users/cnorman/.rvm/gems/ruby-2.3.1@ISGPDR/gems/activesupport-5.0.0.rc1/lib/active_support/notifications/instrumenter.rb:21:ininstrument' /Users/cnorman/.rvm/gems/ruby-2.3.1@ISGPDR/gems/activesupport-5.0.0.rc1/lib/active_support/notifications.rb:164:ininstrument' /Users/cnorman/.rvm/gems/ruby-2.3.1@ISGPDR/gems/actionpack-5.0.0.rc1/lib/action_controller/metal/instrumentation.rb:30:inprocess_action' /Users/cnorman/.rvm/gems/ruby-2.3.1@ISGPDR/gems/actionpack-5.0.0.rc1/lib/action_controller/metal/rescue.rb:31:inprocess_action' /Users/cnorman/.rvm/gems/ruby-2.3.1@ISGPDR/gems/actionpack-5.0.0.rc1/lib/abstract_controller/base.rb:126:inprocess' /Users/cnorman/.rvm/gems/ruby-2.3.1@ISGPDR/gems/actionpack-5.0.0.rc1/lib/action_controller/metal.rb:190:indispatch' /Users/cnorman/.rvm/gems/ruby-2.3.1@ISGPDR/gems/actionpack-5.0.0.rc1/lib/action_controller/metal.rb:262:indispatch' /Users/cnorman/.rvm/gems/ruby-2.3.1@ISGPDR/gems/actionpack-5.0.0.rc1/lib/action_dispatch/routing/route_set.rb:50:indispatch' /Users/cnorman/.rvm/gems/ruby-2.3.1@ISGPDR/gems/actionpack-5.0.0.rc1/lib/action_dispatch/routing/route_set.rb:32:inserve' /Users/cnorman/.rvm/gems/ruby-2.3.1@ISGPDR/gems/actionpack-5.0.0.rc1/lib/action_dispatch/journey/router.rb:39:inblock in serve' /Users/cnorman/.rvm/gems/ruby-2.3.1@ISGPDR/gems/actionpack-5.0.0.rc1/lib/action_dispatch/journey/router.rb:26:ineach' /Users/cnorman/.rvm/gems/ruby-2.3.1@ISGPDR/gems/actionpack-5.0.0.rc1/lib/action_dispatch/journey/router.rb:26:inserve' /Users/cnorman/.rvm/gems/ruby-2.3.1@ISGPDR/gems/actionpack-5.0.0.rc1/lib/action_dispatch/routing/route_set.rb:725:incall' /Users/cnorman/.rvm/gems/ruby-2.3.1@ISGPDR/gems/actionview-5.0.0.rc1/lib/action_view/digestor.rb:12:incall' /Users/cnorman/.rvm/gems/ruby-2.3.1@ISGPDR/gems/rack-2.0.0.rc1/lib/rack/etag.rb:25:incall' /Users/cnorman/.rvm/gems/ruby-2.3.1@ISGPDR/gems/rack-2.0.0.rc1/lib/rack/conditional_get.rb:25:incall' /Users/cnorman/.rvm/gems/ruby-2.3.1@ISGPDR/gems/rack-2.0.0.rc1/lib/rack/head.rb:12:incall' /Users/cnorman/.rvm/gems/ruby-2.3.1@ISGPDR/gems/activerecord-5.0.0.rc1/lib/active_record/migration.rb:552:incall' /Users/cnorman/.rvm/gems/ruby-2.3.1@ISGPDR/gems/actionpack-5.0.0.rc1/lib/action_dispatch/middleware/callbacks.rb:38:inblock in call' /Users/cnorman/.rvm/gems/ruby-2.3.1@ISGPDR/gems/activesupport-5.0.0.rc1/lib/active_support/callbacks.rb:97:in__run_callbacks__' /Users/cnorman/.rvm/gems/ruby-2.3.1@ISGPDR/gems/activesupport-5.0.0.rc1/lib/active_support/callbacks.rb:750:in_run_call_callbacks' /Users/cnorman/.rvm/gems/ruby-2.3.1@ISGPDR/gems/activesupport-5.0.0.rc1/lib/active_support/callbacks.rb:90:inrun_callbacks' /Users/cnorman/.rvm/gems/ruby-2.3.1@ISGPDR/gems/actionpack-5.0.0.rc1/lib/action_dispatch/middleware/callbacks.rb:36:incall' /Users/cnorman/.rvm/gems/ruby-2.3.1@ISGPDR/gems/actionpack-5.0.0.rc1/lib/action_dispatch/middleware/executor.rb:12:incall' /Users/cnorman/.rvm/gems/ruby-2.3.1@ISGPDR/gems/actionpack-5.0.0.rc1/lib/action_dispatch/middleware/remote_ip.rb:79:incall' /Users/cnorman/.rvm/gems/ruby-2.3.1@ISGPDR/gems/raygun4ruby-1.1.9/lib/raygun/middleware/rails_insert_affected_user.rb:11:incall' /Users/cnorman/.rvm/gems/ruby-2.3.1@ISGPDR/gems/raygun4ruby-1.1.9/lib/raygun/middleware/rack_exception_interceptor.rb:10:incall' /Users/cnorman/.rvm/gems/ruby-2.3.1@ISGPDR/gems/actionpack-5.0.0.rc1/lib/action_dispatch/middleware/debug_exceptions.rb:49:incall' /Users/cnorman/.rvm/gems/ruby-2.3.1@ISGPDR/gems/actionpack-5.0.0.rc1/lib/action_dispatch/middleware/show_exceptions.rb:31:incall' /Users/cnorman/.rvm/gems/ruby-2.3.1@ISGPDR/gems/railties-5.0.0.rc1/lib/rails/rack/logger.rb:36:incall_app' /Users/cnorman/.rvm/gems/ruby-2.3.1@ISGPDR/gems/railties-5.0.0.rc1/lib/rails/rack/logger.rb:24:inblock in call' /Users/cnorman/.rvm/gems/ruby-2.3.1@ISGPDR/gems/activesupport-5.0.0.rc1/lib/active_support/tagged_logging.rb:70:inblock in tagged' /Users/cnorman/.rvm/gems/ruby-2.3.1@ISGPDR/gems/activesupport-5.0.0.rc1/lib/active_support/tagged_logging.rb:26:intagged' /Users/cnorman/.rvm/gems/ruby-2.3.1@ISGPDR/gems/activesupport-5.0.0.rc1/lib/active_support/tagged_logging.rb:70:intagged' /Users/cnorman/.rvm/gems/ruby-2.3.1@ISGPDR/gems/railties-5.0.0.rc1/lib/rails/rack/logger.rb:24:incall' /Users/cnorman/.rvm/gems/ruby-2.3.1@ISGPDR/gems/request_store-1.3.1/lib/request_store/middleware.rb:9:incall' /Users/cnorman/.rvm/gems/ruby-2.3.1@ISGPDR/gems/actionpack-5.0.0.rc1/lib/action_dispatch/middleware/request_id.rb:24:incall' /Users/cnorman/.rvm/gems/ruby-2.3.1@ISGPDR/gems/rack-2.0.0.rc1/lib/rack/runtime.rb:22:incall' /Users/cnorman/.rvm/gems/ruby-2.3.1@ISGPDR/gems/activesupport-5.0.0.rc1/lib/active_support/cache/strategy/local_cache_middleware.rb:28:incall' /Users/cnorman/.rvm/gems/ruby-2.3.1@ISGPDR/gems/actionpack-5.0.0.rc1/lib/action_dispatch/middleware/executor.rb:12:incall' /Users/cnorman/.rvm/gems/ruby-2.3.1@ISGPDR/gems/actionpack-5.0.0.rc1/lib/action_dispatch/middleware/static.rb:136:incall' /Users/cnorman/.rvm/gems/ruby-2.3.1@ISGPDR/gems/rack-2.0.0.rc1/lib/rack/sendfile.rb:111:incall' /Users/cnorman/.rvm/gems/ruby-2.3.1@ISGPDR/gems/rack-cors-0.4.0/lib/rack/cors.rb:80:incall' /Users/cnorman/.rvm/gems/ruby-2.3.1@ISGPDR/gems/railties-5.0.0.rc1/lib/rails/engine.rb:522:incall' /Users/cnorman/.rvm/gems/ruby-2.3.1@ISGPDR/gems/puma-3.4.0/lib/puma/configuration.rb:224:incall' /Users/cnorman/.rvm/gems/ruby-2.3.1@ISGPDR/gems/puma-3.4.0/lib/puma/server.rb:569:inhandle_request' /Users/cnorman/.rvm/gems/ruby-2.3.1@ISGPDR/gems/puma-3.4.0/lib/puma/server.rb:406:inprocess_client' /Users/cnorman/.rvm/gems/ruby-2.3.1@ISGPDR/gems/puma-3.4.0/lib/puma/server.rb:271:inblock in run' /Users/cnorman/.rvm/gems/ruby-2.3.1@ISGPDR/gems/puma-3.4.0/lib/puma/thread_pool.rb:114:in`block in spawn_thread' Completed 500 Internal Server Error in 193ms (Views: 1.5ms)